将列表转换为字符串? [英] convert list to string?
问题描述
我想知道是否有一种方法可以将我的列表转换为字符串.
I was wondering if there was a way to convert my List into a String.
示例:是否可以将MyList = ['a', 'b', 'c', 'd', 'e']
转换为MyString = "abcde"
?
Example: Is there a way to convert MyList = ['a', 'b', 'c', 'd', 'e']
to MyString = "abcde"
?
原因:我正在尝试从这5个字母中提取单词:袋子,坏东西,出租车,床上...
Reason: I am trying to make words out of those 5 letters: bag, bad, cab, bed...
我尝试创建一个显示MyList._contains_("bad")
的标签,但是由于坏"不在整个列表中,所以它不起作用,但是"b","a","d"分别在列表中.
I tried creating a Label that shows MyList._contains_("bad")
but it doesn't work since "bad" is not in the list as a whole, but 'b', 'a', 'd' are in the list individually.
所以我想如果将整个列表转换为一个字符串,我将可以使用类似
MyString._contains_("bad")
,并在标签中显示单词.
So I thought if I convert the entire List to one String, I would be able to use something like
MyString._contains_("bad")
and have the word show in the Label.
有没有办法将所有这些转换为一个字符串? 还是有一种更有效的方法来解决此问题?
So is there a way to convert all this to one string? Or is there a more efficient way to solve this issue?
谢谢
推荐答案
>>> MyList = ['a', 'b', 'c', 'd', 'e']
>>> ''.join(MyList)
'abcde'
您其他问题的解决方案
>>> MyList = ['a', 'b', 'c', 'd', 'e']
>>> all(letter in MyList for letter in 'bad')
True
>>> all(letter in MyList for letter in 'test')
False
这篇关于将列表转换为字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!