【发布时间】:2014-01-11 06:44:45
【问题描述】:
我有一个包含字符串的元组列表 例如:
[('this', 'is', 'a', 'foo', 'bar', 'sentences')
('is', 'a', 'foo', 'bar', 'sentences', 'and')
('a', 'foo', 'bar', 'sentences', 'and', 'i')
('foo', 'bar', 'sentences', 'and', 'i', 'want')
('bar', 'sentences', 'and', 'i', 'want', 'to')
('sentences', 'and', 'i', 'want', 'to', 'ngramize')
('and', 'i', 'want', 'to', 'ngramize', 'it')]
现在我希望将每个字符串连接到一个元组中以创建一个空格分隔的字符串列表。 我使用了以下方法:
NewData=[]
for grams in sixgrams:
NewData.append( (''.join([w+' ' for w in grams])).strip())
它工作得很好。
但是,我拥有的列表有超过一百万个元组。所以我的问题是这种方法是否足够有效,或者是否有更好的方法来做到这一点。 谢谢。
【问题讨论】:
标签: python string list tuples concatenation