Has been translated into Python.
def FindOnly(list): for i in range(len(list)): if list[i] not in list[:i]: if list[i] not in list[(i+1):]: return list[i]
f=a=>a.sort()[0]!=a[1]?a[0]:a[0]==(a=a.pop())?'Error':a- def FindOnly(list):
- for i in range(len(list)):
- if list[i] not in list[:i]:
- if list[i] not in list[(i+1):]:
- return list[i]
test.assert_equals(FindOnly([1,1,4]),4) 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')
describe("Solution", function() {it("simple", function() {Test.assertEquals(f([1,1,4]),4);Test.assertEquals(f([1,4,1]),4);Test.assertEquals(f([4,1,1]),4);Test.assertEquals(f(['AD','Ad','Ad']),'AD');Test.assertEquals(f(['Ad','AD','Ad']),'AD');Test.assertEquals(f(['Ad','Ad','AD']),'AD');Test.assertSimilar(f(['null','nulll','null']),'nulll');});it("wrong", function() {Test.assertEquals(f([undefined,undefined,undefined,undefined]),'Error');});});- test.assert_equals(FindOnly([1,1,4]),4)
- 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')