What is the difference between a list comprehension and a set comprehension. Basically, a process step is the only thing sometimes. As seen below, the set_comp results are completed during the query, whereas the list_comp results in line 04 still need to have a set() operation applied after the fact, should a set truly be required. >>> a = [1,2,1,1,2,3,3,2,1,1,1,2,3,4,9,8,1,7,7,7,7,7]
>>> list_comp = [ i for i in a if i >3 ]
>>> set_comp = { i for i in a if i > 3 }
>>> list_comp
[4, 9, 8, 7, 7, 7, 7, 7]
>>> set_comp
set([8, 9, 4, 7])>>> a = [5,6,5,6,5,6,5,6,5,6,4,4]
>>> b = [5,6]
>>> lc = [ x*y for x in a for y in b]
>>> sc = { x*y for x in a for y in b }
>>> lc [25, 30, 30, 36, 25, 30, 30, 36, 25, 30, 30,
36, 25, 30, 30, 36, 25, 30, 30, 36, 20, 24, 20, 24]
>>> sc {24, 25, 36, 20, 30}
>>> |