def FindOnly(list): comparable_list = [(str(x), i) for i, x in enumerate(list)] comparable_list.sort() for i in range(-1, len(list)-1): if comparable_list[i][0] != comparable_list[i-1][0] and comparable_list[i][0] != comparable_list[i+1][0]: return list[comparable_list[i][1]]
- def FindOnly(list):
try:return [i for i in list if list.count(i)==1][0]except:return "Error"- comparable_list = [(str(x), i) for i, x in enumerate(list)]
- comparable_list.sort()
- for i in range(-1, len(list)-1):
- if comparable_list[i][0] != comparable_list[i-1][0] and comparable_list[i][0] != comparable_list[i+1][0]:
- return list[comparable_list[i][1]]
test.assert_equals(FindOnly([1,1,4]),4) test.assert_equals(FindOnly([4,1,4]),1) test.assert_equals(FindOnly([1,4,1]),4) test.assert_equals(FindOnly([4,1,1]),4) test.assert_equals(FindOnly(['AD','Ad','Ad']),'AD') test.assert_equals(FindOnly(['Ad','AD','Ad']),'AD') test.assert_equals(FindOnly(['Ad','Ad','AD']),'AD') test.assert_equals(FindOnly(['null','nulll','null']),'nulll') test.assert_equals(FindOnly(["A",4,"A",1,1,"AD","AD"]),4)
- test.assert_equals(FindOnly([1,1,4]),4)
- test.assert_equals(FindOnly([4,1,4]),1)
- test.assert_equals(FindOnly([1,4,1]),4)
- test.assert_equals(FindOnly([4,1,1]),4)
- test.assert_equals(FindOnly(['AD','Ad','Ad']),'AD')
- test.assert_equals(FindOnly(['Ad','AD','Ad']),'AD')
- test.assert_equals(FindOnly(['Ad','Ad','AD']),'AD')
- test.assert_equals(FindOnly(['null','nulll','null']),'nulll')
- test.assert_equals(FindOnly(["A",4,"A",1,1,"AD","AD"]),4)