这是一个例子:
是)我有的
a = ['1'], ['3'], ['3']
我想要的是
a = ['1', '3', '3']
如何使用Python 3.x解决这个问题
编辑
这是我正在处理的代码.
from itertools import chain
def compteur_voyelle(str):
list_string = "aeoui"
oldstr = str.lower()
text = oldstr.replace(" ", "")
print(text)
for l in list_string:
total = text.count(l).__str__()
answer = list(chain(*total))
print(answer)
compteur_voyelle("Saitama is the One Punch Man.")
控制台结果:
saitamaistheonepunchman.
['4']
['2']
['1']
['1']
['2']
解决方法:
你可以使用itertools.chain.
In [35]: from itertools import chain
In [36]: a = ['1'], ['3'], ['3']
In [37]: list(chain(*a))
Out[37]: ['1', '3', '3']
要么
In [39]: list(chain.from_iterable(a))
Out[39]: ['1', '3', '3']
标签:python,python-3-x
来源: https://codeday.me/bug/20190722/1503617.html