python dictionary add key value using lambda

Solutions on MaxInterview for python dictionary add key value using lambda by the best coders in the world

showing results for - "python dictionary add key value using lambda"
Larissa
25 Mar 2020
1lamb = lambda a, b: dict[a] = b
2# SyntaxError: cannot assign to lambda
3# use this instead
4lamb = lambda a, b: dict.setdefault(a, b)
5###############################################################################
6# in my case, i use escape in order to make line don't exceed 79 characters
7some_long_deep_multiple_condition:
8                  dict[list(dict.keys())[-1]]\
9    			  [str1[:int(a)]] = int(str1[int(b):])
10                  dict[list(dict.keys())[-1]]\
11    			  [str2[:int(a)]] = int(str2[int(b):])
12# instead using that, i use this
13lamb = lambda a, b: dict[list(dict.keys())[-1]].setdefault(a, b)
14some_long_deep_multiple_condition:
15                  lamb(str1[:int(a)], int(str1[int(b):]))
16                  lamb(str2[:int(a)], int(str2[int(b):]))