/    Sign up×
Community /Pin to ProfileBookmark

How do I get a list of characters in a string in Python?

Depends on what you want to do with them. If you want to see how many times one was used, you could count them:

from collections import Counter
in_string = “For £10 pounds you can get $20^, in my dreams!!!”
c = Counter(in_string)
print(c)
Result:

Counter({‘ ‘: 9, ‘o’: 3, ‘n’: 3, ‘!’: 3, ‘r’: 2, ‘0’: 2, ‘u’: 2, ‘d’: 2, ‘s’: 2, ‘y’: 2, ‘a’: 2, ‘e’: 2, ‘m’: 2, ‘F’: 1, ‘£’: 1, ‘1’: 1, ‘p’: 1, ‘c’: 1, ‘g’: 1, ‘t’: 1, ‘$’: 1, ‘2’: 1, ‘^’: 1, ‘,’: 1, ‘i’: 1})
If you just want to know which were used you can use a set, and then sort them if you like:

s = set(in_string)
print(“”.join(sorted(s)))
Result:

!$,012F^acdegimnoprstuy£

to post a comment

3 Comments(s)

Copy linkTweet thisAlerts:
@AllisonGarnerSep 09.2022 — To convert a string to list of characters in Python, use the list() method to typecast the string into a list. The list() constructor builds a list directly from an iterable, and since the string is iterable, you can construct a list from it.
Copy linkTweet thisAlerts:
@marionlankfordSep 13.2022 — To convert a string to list of characters in Python, use the list() method to typecast the string into a list. The list() constructor builds a list directly from an iterable, and since the string is iterable, you can construct a list from it.
Copy linkTweet thisAlerts:
@futureacadSep 13.2022 — visit https://rooman.net/future-skills-program/full-stack-web-development/ [https://rooman.net/future-skills-program/full-stack-web-development/](https://)
×

Success!

Help @SubhanUllah spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...