Created
May 30, 2022 13:37
-
-
Save les-peters/aa7ce4444e5cc88a7a57f37df63ba4bb to your computer and use it in GitHub Desktop.
all unique
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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