-1
$\begingroup$

I have a list.

list = ['It is a delightfully naive and entertaining movie',
        'The songs are boring and dated in 2009',
        'was a great movie from genre director Luc Besson']

and I want a result like:

list_result = [ It is a delightfully naive and entertaining movie The songs are boring and dated in 2009 was a great movie from genre director Luc Besson]

how I can do this? (list_result can also be a corpus.)

$\endgroup$

3 Answers 3

1
$\begingroup$
result = ""
for sentence in list:
    result += sentence
    result += " "
list_result = [result]

Go over list comprehension if you want a more pythonic way to do it, here is the most understandable to begin.

$\endgroup$
1
$\begingroup$

Firstly, this question isn't suitable for Datascience, go over to Stackoverflow for these kind of questions.

Secondly, I advice you to look up some introductory tutorials for Python. The Python wiki has a whole list of these here.

Lastly, as to answer your question:

l = ['AB', 'CD', 'EF']
o = ' '.join(l)

output:

>>> o
'AB CD EF'
$\endgroup$
1
$\begingroup$

Suppose you have the following DF:

In [11]: df
Out[11]:
                                                 txt
0  It is a delightfully naive and entertaining movie
1             The songs are boring and dated in 2009
2   was a great movie from genre director Luc Besson

Use Series.str.cat:

In [12]: df['txt'].str.cat(sep=' ')
Out[12]: 'It is a delightfully naive and entertaining movie The songs are boring and dated in 2009 was a great movie from genre director Luc Besson'
$\endgroup$

Not the answer you're looking for? Browse other questions tagged or ask your own question.