Skip to content

Instantly share code, notes, and snippets.

@EricKotato
Created July 27, 2018 14:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricKotato/8996beb35a2342b8c5d8a3f551a9e1c8 to your computer and use it in GitHub Desktop.
Save EricKotato/8996beb35a2342b8c5d8a3f551a9e1c8 to your computer and use it in GitHub Desktop.
def checkUniqueDict(s):
if not s:
return False
symbols = {}
for c in s:
if symbols.get(c):
return False
else:
symbols[c] = True
return True
def checkUniqueList(s):
if not s:
return False
symbols = []
for c in s:
if c in symbols:
return False
else:
symbols.append(c)
return True
print("dict:")
print("abcdefg ", checkUniqueDict("abcdefg "))
print("abcafg", checkUniqueDict("abcafg"))
print(" Try ", checkUniqueDict(" Try "))
print(" ", checkUniqueDict(" "))
print("", checkUniqueDict(""))
print()
print("list:")
print("abcdefg ", checkUniqueList("abcdefg "))
print("abcafg", checkUniqueList("abcafg"))
print(" Try ", checkUniqueList(" Try "))
print(" ", checkUniqueList(" "))
print("", checkUniqueList(""))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment