Fork me on GitHub
# def my_sum(x,y):
# return x+y
# lambda x,y:x+y
# print((lambda x,y:x+y)(1,2)) # 3
# salaries={
# 'siry':3000,
# 'tom':7000,
# 'lili':10000,
# 'jack':2000
# }

# zip()
# # print(max(salaries)) # tom
# s='hello'
# l=[1,2,3,4]
# g=zip(s,l)
# # print(g) # <zip object at 0x000001EBE6AE01C8>
# # print(list(g)) # [('h', 1), ('e', 2), ('l', 3), ('l', 4)]

# g=zip(salaries.values(),salaries.keys())
# print(list(g)) # [(3000, 'siry'), (7000, 'tom'), (10000, 'lili'), (2000, 'jack')]

# def func(k):
# return salaries[k]
# max(salaries,key=func)
# print(max(salaries,key=func)) # lili
# print(max(salaries,key=lambda k:salaries[k])) # lili
# print(min(salaries,key=lambda k:salaries[k])) # jack

# sorted()
# print(sorted(salaries)) # ['jack', 'lili', 'siry', 'tom']
# print(sorted(salaries,key=lambda k:salaries[k])) # ['jack', 'siry', 'tom', 'lili']
# print(sorted(salaries,key=lambda k:salaries[k],reverse=True)) # ['lili', 'tom', 'siry', 'jack']
# names=['One','Two','Three']
# l=[]
# for name in names:
# res='%s_love'%name
# l.append(res)
#
# print(l) # ['One_love', 'Two_love', 'Three_love']

# map()
# g=map(lambda name:'%s_love'%name,names)
# # print(g) # <map object at 0x0000027316202F08>
# print(list(g)) # ['One_love', 'Two_love', 'Three_love']

# filter()
# names=['One_love', 'Two_love', 'Three_love','egon']
# g=filter(lambda x:x.endswith('love'),names)
# # print(g) # <filter object at 0x0000021F63392F48>
# print(list(g)) # ['One_love', 'Two_love', 'Three_love']

# reduce()
# from functools import reduce
# g=reduce(lambda x,y:x+y,range(1,101))
# print(g) # 5050

# from functools import reduce
# g=reduce(lambda x,y:x+y,range(1,101),100)
# print(g) # 5150
posted on 2019-12-09 20:30  OBOS  阅读(137)  评论(0编辑  收藏  举报