[ create a new paste ] login | about

Link: http://codepad.org/0zzx030X    [ raw code | output | fork ]

minitech - Python, pasted on Apr 27:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
def exactlyTwo(l):
    for i in xrange(0, len(l)):
        try:
            j = l.index(l[i], i + 1)

            try:
                l.index(l[i], j + 1)
            except ValueError:
                return True
        except ValueError:
            # Do nothing. Not sure how to do that in Python.
            0

    return False

print exactlyTwo(["one", "one", "two"])
print exactlyTwo(["one", "two", "two"])
print exactlyTwo(["one", "two", "three"])


Output:
1
2
3
True
True
False


Create a new paste based on this one


Comments: