2.链式函数调用
可以在一行代码内调用多个函数
def add(a,b):
return a+b
def subtract(a,b):
return a-b
a,b=4,5
print((subtract if a>b else add)(a,b))
3.检查重复项
检查两个列表是否有重复项
def has_duplicate(list1):
if len(list1)==len(set(list1)):
print("没有")
else:
print("有")
x=[1,2,3,4,5]
y=[1,2,2,3,4]
has_duplicate(x)
has_duplicate(y)
4.合并两个字典
用于合并两个字典
注意:在python3.5及更高的python版本中
def merge_dicts(a,b):
return {
**a,**b