4 ms·
Peter, we need to talk. http://docs.python.org/library/itertools.html http://docs.python.org/library/itertools.html "combinations()" is a built in. No need t
by keenerd 17y ago
Peter, we need to talk.
http://docs.python.org/library/itertools.html http://docs.python.org/library/itertools.html
"combinations()" is a built in. No need to re-implement it. Also, nested [... for ... for ... for] is silly. Just use "product()", documented on the same page.
[''.join(card) for card in product('123', 'RGP', '@O=', 'OSD')]
They say that six months after learning the itertools module, people give up on Python for Lisp. Which would be hilarious, in your case.
- JeffJenkins 17y agoIt's entirely possible he wrote this before itertools existed. Like in the IAQ where he says things like: "Better to stick with x += 1, which was added in Python 2.0. " ( http://norvig.com/python-iaq.html http://norvig.com/python-iaq.html )
- deleted 17y ago[deleted]
- abyx 17y agoI've asked him about this, here is his reply: "[...] about itertools -- I guess I got the impression that itertools is deprecated in 3.0, or at least that Guido doesn't much like it, so I have stayed away from it. And itertools.combinations is only in 2.6, so I think I will leave things as is, for those still stuck in 2.5."
- keenerd 17y agoCombinations is also in +3.0. Otherwise a valid concern. (Been burned by that one myself.) I can't find the source, but there might be some confusion between map/filter/reduce and itertools. Guido does not like map/filter/reduce and wants to get rid of them. Itertools is a huge part of Python 3.0. Everything is an iterator in the language. And the docs underwent a major rewrite with the 3.0 release. It is not going to be deprecated.