Some people, when confronted with a problem, think "I know, I'll use itertools."
Now they have
next(takewhile(not_, count())) problems.
Since I've been asked about this multiple times now:
It's a reference to "Now they have two problems" about regular expressions.
next(takewhile(not_, count())) is guaranteed to give you
0, and pretty efficiently… but it's not exactly readable. Which is the joke.
itertools does solve all your problems, but you don't always need to use it.
If you don't grasp the paradigm, go read David Beazley's presentations. Once you do: "I've got a CSV, and I want to group the rows by…" Pass a
groupby. "I've got a bunch of values, and I want to take them 4 at a time and…" Use
grouper from the recipes. "I've got a file, and I want to take each pair of adjacent lines and…"
next one copy, and
zip them. And so on.
But of course some problems have an even easier solution, and once you start thinking in terms of sequences of transformations on iterators, sometimes you'll miss the easier answer.
(The exact same thing happens with
numpy, of course.)
San Francisco, CA
Member for 1 year, 11 months
0 profile views
Last seen Sep 9 '18 at 3:53
- Stack Overflow 293.5k 293.5k 3232 gold badges460460 silver badges552552 bronze badges
- Worldbuilding 2.8k 2.8k 55 silver badges1818 bronze badges
- Linguistics 2.5k 2.5k 55 silver badges1717 bronze badges
- Meta Stack Exchange 962 962 66 silver badges1111 bronze badges
- Code Golf 467 467 22 silver badges77 bronze badges
- View network profile
Top network posts
- 864 Why is "1000000000000000 in range(1000000000000001)" so fast in Python 3?
- 271 Python assigning multiple variables to same value? list behavior
- 260 What are the differences between the threading and multiprocessing modules?
- 244 Is it possible to "hack" Python's print function?
- 243 Visibility of global variables in imported modules
- 186 How to unpack and pack pkg file?
- 176 Why is there no xrange function in Python3?
- View more network posts →