Created
October 15, 2019 12:49
-
-
Save alexmacniven/908369b2a8930045e1a878b7f609c602 to your computer and use it in GitHub Desktop.
Finds unique characters in a string
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
# 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