so how can I get a word like dog and make it into "d","o","g" with a function in python? Thanks.
Asked
Active
Viewed 30 times
-2
-
2Use `list("dog")` – Dani Mesejo Nov 24 '21 at 17:41
-
It's not clear why you'd post this question when if you searched on this site, or on Google, you'd find many solutions. It wastes people's time when you fill up this site with obvious duplicate questions. Please see: [How much research effort is expected of Stack Overflow users?](https://meta.stackoverflow.com/q/261592/6273251) – Random Davis Nov 24 '21 at 17:43
-
Please put in the bare minimum amount of research effort before posting here in accordance with [ask] - this is something you can find here with a quick Google search. – esqew Nov 24 '21 at 17:44
1 Answers
1
Strings are iterable: each element is a single-character string.
for c in "dog":
print(c)
d
o
g
list
takes an arbitrary iterable as an argument, and creates a list with one element per value from that iterable.
>>> list("dog")
['d', 'o', 'g']

chepner
- 497,756
- 71
- 530
- 681