Skip to content

Instantly share code, notes, and snippets.

@les-peters
Created May 30, 2022 13:37
Show Gist options
  • Save les-peters/aa7ce4444e5cc88a7a57f37df63ba4bb to your computer and use it in GitHub Desktop.
Save les-peters/aa7ce4444e5cc88a7a57f37df63ba4bb to your computer and use it in GitHub Desktop.
all unique
question = """
Write a function that determines if all the characters in a given string
are unique. Can you do this without making any new variables? You choose
if you want to include capitalization in your consideration for this one,
as a fun challenge.
Example:
> allUnique('Cassidy')
> false
> allUnique('cat & dog')
> false
> allUnique('cat+dog')
> true
"""
def allUnique(string):
u = {}
for ch in string:
if not ch in u:
u[ch] = 0
u[ch] += 1
return len(u) == len(string)
print(allUnique('Cassidy'))
print(allUnique('cat & dog'))
print(allUnique('cat+dog'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment