def is_winner(l):
#if len(set(l)) == 2 #if you want to return True on any 2 elements are the same in the list
if len(set(l)) == 1: #if you want to return True if all elements are the same
return 'You won!'
else:
return 'You lost!'
测试:
In [11]: is_winner(['7','7','7'])
Out[11]: 'You won!'
您可以使用set方法检查案例中是否有相同的元素。你知道吗
示例:
我想你需要:
测试:
您可以在这里使用
set()
,它将只返回列表中唯一的元素。如果集合中的元素少于原始列表,则原始列表中存在重复项。你知道吗相关问题 更多 >
编程相关推荐