Skip to content

Instantly share code, notes, and snippets.

@alexmacniven
Created October 15, 2019 12:49
Show Gist options
  • Save alexmacniven/908369b2a8930045e1a878b7f609c602 to your computer and use it in GitHub Desktop.
Save alexmacniven/908369b2a8930045e1a878b7f609c602 to your computer and use it in GitHub Desktop.
Finds unique characters in a string
# Here's the original string.
_string = "abcdde"
# Cast the string into a set of characters.
# Remember sets have all unique elements.
char_set = set(_string)
# Create a string from the character set.
unique_string = "".join(char_set)
# Count the number of times each character appears in the original string.
for char in char_set:
entries = _string.count(char)
print(f"{char} has {entries} entries.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment