Lodash for Python?

Question:

Is there a library or something similar to lodash, for Python? We use the library extensively on our API and while we move on to creating a series of Python workers, it would make sense to create a similar structure to our API syntactics.

Asked By: stackunderflow

||

Answers:

Well I’m not sure if this is exactly what you’re looking for but when I think of javascript libraries like underscore and Lodash, I think of libraries that add more functional programming functions(though I do believe both underscore and lodash have a little more utility than that) to a language.

There are a bunch of Python Libraries that try and add some of the same functionality. A quick search got me pytoolz https://github.com/pytoolz/toolz which I don’t have much experience with but looks interesting. If that isn’t what you’re looking for, try searching for other functional programming python libraries until you find one you like.

Hope that helped

Answered By: jmdevivo

pydash is exactly like lodash, only for Python.

Answered By: Adam Boduch

pydash is something which you can use as a replacement of lodash in python. Almost everything is covered under it, the names of functions are also similar just keeping python’s conventions as is.

Important: I’ve been using pydash for around 07 months, It helped me a lot. One thing which you should not forget is, avoid using pydash functions directly on self, its behaviour is very erratic and gives random results. I’m showing one example below.

Sample Class

class MyClass:
    def get(self):
       self.obj = {}
       self.obj['a'] = True

Usage
class TestClass:
def init(self):
self.inst = MyClass()

   def test_function(self):
      # **Not Recommended Method**
      # _.get(self, "inst.a")    # shows random behavior

      # **Highly recommended**
      _.get(self.inst, "a")     # Will always return True
Answered By: Mudassirkhan
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.