5 ms·
that's what sets are for. >>> list(set(['1', '2', '3', '1'])) ['1', '3', '2']
by earle 19y ago
that's what sets are for.
>>> list(set(['1', '2', '3', '1']))
['1', '3', '2']
- ivankirigin 19y agoCool More often than not, I do want the count though. I would be surprised if a set didn't use the exact same hashing subroutines that a dict uses. Am I wrong?
- MarkTwinia 19y agoYes, but as gp said, don't bother yourself with these details.
- bootload 19y ago"... list(set(['1', '2', '3', '1'])) ..." Nice earle. That's what I've come to expect from python. There is always a shorter better way. The only difference I've found is the returned list is sorted & broke my test suite. Here's the docs & PEP. - http://docs.python.org/lib/module-sets.html http://docs.python.org/lib/module-sets.html - http://www.python.org/dev/peps/pep-0218/ http://www.python.org/dev/peps/pep-0218/ Thx @Tipjoy for posting this or I'd still be using a 4-6 line clunker.