--
1s='123456'2l={'0'70A'1': 1,'2': 2,'3': 3,'4': 4,'5'75A'6': 6,'7': 7,'8': 8,'9': 9}[s[0]]3 Print(l)
Remove the key element from DIC
1 def Normalize (name): 2 tempn=name.lower (). Capitalize () 3 return TEMPN 4 L1 = [" adam ", " Span style= "COLOR: #800000" >lisa ", bart " ] 5 L2 = list (map (normalize, L1)) Span style= "COLOR: #008080" >6 print (L2)
Capitalize the first letter only, and the rest of the lowercase one uses the string lower () capitalize () function
1 ##sum2num1=[20,30,50]3 Print(SUM (num1[1:]))4 ##multiply5 defprod (L):6 returnReduceLambdax,y:x*y, L)7l3=[1,2,3,4,6]8 Print(Prod (l3[:2]))9 Print(1*2)
List summation and quadrature functions where reduce lambda expressions are used
1 defStr2float (s):2Tempstr=s.split ('.')3Ustr=tempstr[0]+tempstr[1]4 defStr2Num (R):5 return{'0': 0,'1': 1,'2': 2,'3': 3,'4': 4,'5': 5,'6': 6,'7': 7,'8': 8,'9': 9}[r]6Ws=len (tempstr[1])7 returnReduceLambdaX, y:x * + y, map (Str2Num, USTR))/(10**WS)
--str convert the float function. The idea is to remove the decimal point, convert it to an integer, and divide by the number of decimal places.
Map reduce usage str processing lower () capitalize ()