Better way to do this dict comprehesion

Sayth Renshaw flebber.crue at gmail.com
Wed Mar 8 04:52:30 EST 2017


Peter I really like this

The complete code: 

>>> from collections import Counter 
>>> def find_it(seq): 
...     [result] = [k for k, v in Counter(seq).items() if v % 3 == 0] 
...     return result 
... 
>>> test_seq = [20,1,-1,2,-2,3,3,5,5,1,2,4,20,4,-1,-2,5] 
>>> find_it(test_seq) 

But what may be the smallest thing in this i had no idea I could do [result] = blah and get a generator on the return variable that seems insane.

Cheers

Sayth


More information about the Python-list mailing list