您如何加入列表中的所有项目? [英] How do you join all items in a list?

查看:54
本文介绍了您如何加入列表中的所有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个列表,它将一个单词的每个字母逐个添加到该列表中,直到程序运行,我才知道列表中将包含什么.如何将列表中的每个字母连成一个单词?例如将['p', 'y', 't', 'h', 'o', 'n']变成['python'].

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'].

推荐答案

a = ['a', 'b', 'c']
res = "".join(a)

您可以使用再次转换回字母列表:

You can again convert back to list of letters using :

list(res)

这篇关于您如何加入列表中的所有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆