Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python - converting a list of tuples to a list of strings

Tags:

python

I have a list of tuples that looks like this:

[('this', 'is'), ('is', 'the'), ('the', 'first'), ('first', 'document'), ('document', '.')]

What is the most pythonic and efficient way to convert into this where each token is separated by a space:

['this is', 'is the', 'the first', 'first document', 'document .']
like image 808
Tampa Avatar asked Jul 27 '12 21:07

Tampa


1 Answers

Very simple:

[ "%s %s" % x for x in l ]
like image 150
Igor Chubin Avatar answered Sep 19 '22 18:09

Igor Chubin