index find和count是LIst下查找三大方法:
Python index() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,该方法与 python find()方法一样,只不过如果str不在 string中会报一个异常。 Python find() 方法检测字符串中是否包含子字符串 str ,如果指定 beg(开始) 和 end(结束) 范围,则检查是否包含在指定范围内,如果包含子字符串返回开始的索引值,否则返回-1。 Python Count() 方法检测字符串中 str出现了几次。 完美符合题意 class Solution(object): def singleNumber(self, nums): """ :type nums: List[int] :rtype: int """ for i in nums: if nums.count(i)== 1: return i