方法一: 使用列表的 count() 方法取出单独的数
- def find_single(num_list):
- for n in num_list:
- if num_list.count(n) == 1:
- return n
- print(find_single([1,2,2,1,3,4,3]))
方法二: 使用异或方法, 简单快速
- def find_single(num_list):
- EOR = 0
- for n in num_list:
- EOR =EOR^n
- return EOR
- print(find_single([1,2,2,1,3,4,3]))
来源: http://www.bubuko.com/infodetail-2931774.html