In Python 2.6.5, given this list mylist = [20, 30, 25, 20]
Why does this set comprehension not work?
>>> {x for x in mylist if mylist.co
$ python2.6
>>> mylist = [20, 30, 25, 20]
>>> {x for x in mylist if mylist.count(x) >= 2}
File "", line 1
{x for x in mylist if mylist.count(x) >= 2}
^
SyntaxError: invalid syntax
$ python2.7
>>> mylist = [20, 30, 25, 20]
>>> {x for x in mylist if mylist.count(x) >= 2}
set([20])
You can accomplish the results in python2.6 using an explicit set, and a generator:
>>> set(x for x in mylist if mylist.count(x) >= 2)
set([20])