Answers for "python dictionary add key value using lambda"

0

python dictionary add key value using lambda

lamb = lambda a, b: dict[a] = b
# SyntaxError: cannot assign to lambda
# use this instead
lamb = lambda a, b: dict.setdefault(a, b)
###############################################################################
# in my case, i use escape in order to make line don't exceed 79 characters
some_long_deep_multiple_condition:
                  dict[list(dict.keys())[-1]]\
    			  [str1[:int(a)]] = int(str1[int(b):])
                  dict[list(dict.keys())[-1]]\
    			  [str2[:int(a)]] = int(str2[int(b):])
# instead using that, i use this
lamb = lambda a, b: dict[list(dict.keys())[-1]].setdefault(a, b)
some_long_deep_multiple_condition:
                  lamb(str1[:int(a)], int(str1[int(b):]))
                  lamb(str2[:int(a)], int(str2[int(b):]))
Posted by: Guest on May-01-2021

Code answers related to "python dictionary add key value using lambda"

Python Answers by Framework

Browse Popular Code Answers by Language