Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
112 views
in Technique[技术] by (71.8m points)

python - How do you join all items in a list?

I have a list and it adds each letter of a word one by one to this list, I don't know what will be in the list until the program is run. How do I join each letter in the list into one word? e.g. turn ['p', 'y', 't', 'h', 'o', 'n'] into ['python'].

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
a = ['a', 'b', 'c']
res = "".join(a)

You can again convert back to list of letters using :

list(res)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...