Package: lodash-py
Lodash.pyLodash methods in Python.Install with pip$pipinstalllodash-pyUsage# From lodash_py modules import Lodashfromlodash_pyimportLodash# Create instance of Lodash_=Lodash()print(_.find_index(users,lambdao:o["user"]=="barney"))# 0List Methods_.compactCreates an list with all falsey values removed. The values False, None, 0 and "" are falsey.print(_.compact([0,1,False,2,'',3,None]))# [1, 2, 3]_.dropCreates a slice of list with n elements dropped from the beginning.print(_.drop([1,2,3],2))# [3]print(_.drop([1,2,3],5))# []print(_.drop([1,2,3],0))# [1, 2, 3]_.drop_rightCreates a slice of list with n elements dropped from the end.print(_.drop_right([1,2,3]))# [1, 2]print(_.drop_right([1,2,3],2))# [1]print(_.drop_right([1,2,3],5))# []print(_.drop_right([1,2,3],0))# [1, 2, 3]_.find_indexReturns the index of the found element, else -1.users=[{'user':'Benson','active':False},{'user':'Frank','active':False},{'user':'Erik','active':True}]print(_.find_index(users,lambdao:o["user"]=="Benson"))# 0print(_.find_index(users,{'user':'Frank','active':False}))# 1print(_.find_index(users,['active',False]))# 0print(_.find_index(users,'active'))# 2_.from_pairsThis method returns an object composed from key-value pairs.print(_.from_pairs([['a',1],['b',2]]))# {'a': 1, 'b': 2}_.headReturns the first element of list.print(_.head([1,2,3]))# 1print(_.head([]))# None_.initialGets all but the last element of list.print(_.initial([1,2,3]))# [1, 2]_.joinReturns the joined string.print(_.join(["a","b","c"],"~"))# 'a~b~c'print(_.join(["a","b","c","d"],"@"))# 'a@b@c@d'_.pullRemoves all given values from list.print(_.pull(['a','b','c','a','b','c'],'a','c'))# ['b', 'b']_.pull_allThis method is like _.pull except that it accepts a list of values to remove.print(_.pull_all(['a','b','c','a','b','c'],['a','c']))# ['b', 'b']_.pull_atRemoves elements from list corresponding to indexes and returns a list of removed elements.list_example=['a','b','c','d']pulled=_.pull_at(list_example,[1,3]);print(list_example)# ['a', 'c']print(pulled)# ['b', 'd']_.lastReturns the last element of list.print(_.last([1,2,3]))# 3_.takeCreates a slice of list with n elements taken from the beginning.print(_.take([1,2,3]))# [1]print(_.take([1,2,3],2))# [1, 2]print(_.take([1,2,3],5))# [1, 2, 3]print(_.take([1,2,3],0))# [0]_.tailGets all but the first element of list.print(_.tail([1,2,3,4]))# [2, 3, 4]_.uniqCreates a duplicate-free version of an list.print(_.uniq([2,1,2]))# [1, 2]print(_.uniq([3,3,4,4,5,6,6,7]))# [3, 4, 5, 6, 7]_.xorCreates an list of unique values that is the symmetric difference of the given list.
The order of result values is determined by the order they occur in the list.print(_.xor([2,1],[2,3]))# [1, 3]Lang Methods_.cast_listCasts value as an listprint(_.cast_list(1))# [1]print(_.cast_list({'a':1}))# [{'a': 1}]print(_.cast_list('abc'))# ['abc']print(_.cast_list())# []_.comforms_toChecks if dict_input conforms to source by invoking the predicate properties of source with the corresponding property values of dict_input.dict_example={'a':1,'b':2};print(_.conforms_to(dict_example,{"b":lambdan:n>1}))# Trueprint(_.conforms_to(dict_example,{"b":lambdan:n>2}))# False_.gtReturns true if value is greater than other, else false.print(_.gt(3,1))# Trueprint(_.gt(3,3))# Falseprint(_.gt(1,3))# False_.gteReturns true if value is greater than or equal to other, else false.print(_.gte(3,1))# Trueprint(_.gte(3,3))# Trueprint(_.gte(1,3))# False_.is_listChecks if value is classified as a List.print(_.is_list([1,2,3]))# Trueprint(_.is_list("abc"))# Falseprint(_.is_list(None))# Falseprint(_.is_list(12))# Falseprint(_.is_list({"a":12}))# FalseMath Methods_.addAdds two numbers.print(_.add(6,4))# 10_.divideDivide two numbers.print(_.divide(6,4))# 1.5_.maxComputes the maximum value of list.print(_.max([4,2,8,6]))# 8_.minComputes the minimum value of list.print(_.min([4,2,8,6]))# 2