0

itertools and functools are good, but there are many basic things they don't include. For example, "find first element in sequence matching predicate", or "flatten a list", or "get element from a nested dict using a sequence of keys".

I'm talking about relatively simple functions that you can implement yourself in under 20 lines of code, using only standard library. Not some sophisticated algorithms and data structures.

I've recently discovered pydash, it's quite powerful, but I don't find it very Pythonic.

Which general-purpose utility package(s) can you recommend?

  • There may not be libraries for most of what you've mentioned because Python handles list-based work very neatly on its own. Flattening a list, for instance, could be simply [ flatten_op(x) for x in list_of_objects ] so not much need for a library like you'd have in other languages. – ATG Oct 12 '18 at 18:19
2

I don't know if you will find this any more Pythonic than pydash, but you could try more-itertools. Its name implies it is modeled after Python's included itertools module.

Of your examples, it has locate to find elements matching a predicate and flatten or collapse to flatten a list (one or arbitrary levels, respectively). I don't know it well enough to know if it has your third example (but I doubt it does).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.