Concatenate elements of a tuple in a list in python

前端 未结 3 1540
执笔经年
执笔经年 2020-12-09 16:38

I have a list of tuples that has strings in it For instance:

[(\'this\', \'is\', \'a\', \'foo\', \'bar\', \'sentences\')
(\'is\', \'a\', \'foo\', \'bar\', \'         


        
3条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2020-12-09 17:25

    For a lot of data, you should consider whether you need to keep it all in a list. If you are processing each one at a time, you can create a generator that will yield each joined string, but won't keep them all around taking up memory:

    new_data = (' '.join(w) for w in sixgrams)
    

    if you can get the original tuples also from a generator, then you can avoid having the sixgrams list in memory as well.

提交回复
热议问题