File tree Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Expand file tree Collapse file tree 1 file changed +19
-0
lines changed Original file line number Diff line number Diff line change 22# -*- coding: utf-8 -*-
33
44from functools import reduce
5+ import re
56
67__author__ = 'Mr.Huo'
78
@@ -22,6 +23,10 @@ def statistics(dic, k):
2223 return dic
2324
2425
26+ def str2int (x , y ):
27+ return x * 10 + y
28+
29+
2530def main ():
2631 # python map()函数,接收两个参数函数、Iterable,map将传入的函数依次作用到序列的每个元素,并把结果作为新的Iterator返回
2732 list1 = [x for x in range (1 , 12 )]
@@ -48,6 +53,20 @@ def main():
4853 redu4 = reduce (statistics , list2 , {})
4954 print (redu4 )
5055
56+ # 将字符串的首字母大写,其他的小写
57+ names = ['adam' , 'LISA' , 'barT' ]
58+ b = lambda x : x [0 ].upper () + x [1 :].lower ()
59+ print (b (names [2 ]))
60+ new_names = list (map (lambda x : x [0 ].upper () + x [1 :].lower (), names ))
61+ print (new_names )
62+
63+ # 将数字字符串转换成一个数
64+ num_str = '1003750'
65+ num = reduce (lambda x , y : x * 10 + y , map (int , num_str ))
66+ print (num , type (num ))
67+ num1 = reduce (lambda x , y : x / 10 + y , map (int , num_str [::- 1 ]))
68+ print (num1 , type (num1 ))
69+
5170
5271if __name__ == '__main__' :
5372 main ()
You can’t perform that action at this time.
0 commit comments