voted={}
def check_voter(name):
if voted.get(name):
#使用函数get来返回是否存在。不存在返回None ,进入else:
print(‘kick them out!’)
else:
voted[name]=True #将其姓名加入散列表
print(‘let them vote’)
check_voter(‘tom’)
check_voter(‘jerry’) check_voter(‘jerry’)
散列表
最新推荐文章于 2022-08-04 16:29:51 发布