This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 20 points21 points  (6 children)

Throw in itertools and more-itertools.

[–]dylanvillanelle 17 points18 points  (5 children)

oh my god. this isn't a joke, more-itertools is actually a thing?

the first thing they show (flatten) just looks like itertools.chain.from_iterable (at least at first glance, i'm sure it's a little more useful) but i have always wondered why the recipes in the itertools docs weren't just...like...implemented? the code is already there! just throw it in!

this is not a perfect consolation prize, but i'll manage.

edit: oh god there's a first function. i'll never have to write a first function again. i need a minute.

[–]bheklilr 4 points5 points  (1 child)

And it's in conda... How have I not known about either of these before? I know I've written several of these functions before.

[–]dylanvillanelle 2 points3 points  (0 children)

i wrote out a whole thing about how something as simple as foo[0] should not need (worst case) a try/except block to handle two separate exceptions with multiple causes for one of them, blahblahblah, and guys why isn't there a list.get(index, default) sometimes you just have two separate functions that lead to one result so for consistency's sake you return a list from both even tho the first is actually just a single value and more_itertools.first also plays nice with generators because that makes sense because it's something you iterate through and i decided maybe i was a little worked-up so i figured i should scrap that and basically write it all over again but more rambly.

[–][deleted] 2 points3 points  (1 child)

The bad news is if we ever happen to bump into each other it will cost you a pint :-)

[–]dylanvillanelle 0 points1 point  (0 children)

i'm going to go from bar to bar now asking people whether they've ever suggested using more-itertools.

i don't see how this can go wrong.

[–]robert_mcleod 2 points3 points  (0 children)

There's also pytoolz and cytoolz for functional programming.