Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save blubberdiblub/b9510567b1e7f0988ee2f1cbf60e5019 to your computer and use it in GitHub Desktop.
Save blubberdiblub/b9510567b1e7f0988ee2f1cbf60e5019 to your computer and use it in GitHub Desktop.
//Previous code
a = list(map(int, raw_input().split()))
for i in a:
if a.count(i) == 1:
print i
break
// Current code
from collections import Counter
a = list(map(int, raw_input().split()))
b = Counter(a)
onlies = [k for k,v in b if v == 1]
print onlies
# one way using sets
present = set()
morelies = set()
for i in a:
if i in present:
morelies.add(i)
else:
present.add(i)
onlies = present - morelies
print(onlies)
# another way using sets
onlies = set()
morelies = set()
for i in a:
if i in morelies:
pass
elif i in onlies:
morelies.add(i)
onlies.remove(i)
else:
onlies.add(i)
print(onlies)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment