Is there any way to do what this implies:
a, b, ... = count()
The idea is to match the first two values from the (infinite, in this case) iterator, and discard the rest.
The best I can do is the clunky:
a, b = islice(count(), 0, 2)
which requires you to count the number of entries on the left hand side.
Is there a cool hack I am missing?
No, there is no simple way to that unless you explicitly tell the amount of elements you want.
There has been a lot of discussion (I think in the end of last year when they were introducing the enum library) in the Python-ideas mail group about this and nobody could agree to a way of solving this problem.
For finite iterators, on Python 3 you can use:
a, b, *_ = thing()
Where the _ variable may be ignored.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With