Better way to do this dict comprehesion
jussi.piitulainen at helsinki.fi
Wed Mar 8 06:57:05 EST 2017
Sayth Renshaw writes:
> 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
You confirmed to Chris that you want the item that occurs an odd number
of times. The test for that is v % 2 == 1.
Or just v % 2, given that 0 and 1 are considered false and true, resp.
But v % 3 == 0 is something else.
More information about the Python-list