TL;DR
The company develops the front side with React and the back end with Django.
I often use a library called lodash
on the front side, but it's insanely convenient, and when I write Python after that, I sometimes feel frustrated because there is no lodash
.
One day when I was suffering from such frustration, I found a library called pydash
, which can be called a Python version of lodash
, so I will introduce it.
It is said that the available Ptyhon version is 2.6 or higher, or 3.3 or higher, so I will try it with Python 3.7.6 as appropriate.
$ pip install pydash
>>> import pydash
>>> from pydash import flatten
# Arrays
>>> flatten([1, 2, [3, [4, 5, [6, 7]]]])
[1, 2, 3, [4, 5, [6, 7]]]
>>> pydash.flatten_deep([1, 2, [3, [4, 5, [6, 7]]]])
[1, 2, 3, 4, 5, 6, 7]
>>> pydash.remove([{'name': 'moe', 'age': 40}, {'name': 'larry', 'age': 50}], lambda x: x['age'] < 50)
[{'name': 'moe', 'age': 40}]
# Collections
>>> pydash.map_([{'name': 'moe', 'age': 40}, {'name': 'larry', 'age': 50}], 'name')
['moe', 'larry']
>>> pydash.filter_([{'name': 'moe', 'age': 40}, {'name': 'larry', 'age': 50}], {'age': 40})
[{'name': 'moe', 'age': 40}]
# Functions
>>> curried = pydash.curry(lambda a, b, c: a + b + c)
>>> curried(1, 2)(3)
6
# Objects
>>> pydash.omit({'name': 'moe', 'age': 40}, 'age')
{'name': 'moe'}
# Utilities
>>> pydash.times(3, lambda index: index)
[0, 1, 2]
# Chaining
>>> pydash.chain([1, 2, 3, 4]).without(2, 3).reject(lambda x: x > 1).value()
[1]
It's wonderful. It's not inferior to lodash.
As mentioned above, there are subtle differences in function names such as pydash.map_
and pydash.filter_
.
I think it's quite convenient. The lodash documentation is fairly easy to read, so it seems that development will progress while referring to it.
https://pydash.readthedocs.io/en/latest/ https://lodash.com/
Recommended Posts