-1

a = ['Hi How are you', 'i am doing fine', 'how about you']

Here a is a list of sentences. I need something like this using python.

result = [Hi How are you i am doing fine how about you]

Georgy
  • 12,464
  • 7
  • 65
  • 73
  • `[' '.join(a)]` – CDJB Feb 03 '20 at 11:46
  • I think one of the edits changed the meaning of the question completely. I rolled it back to its initial state. @VivekWilliam, the line `result = [Hi How are you i am doing fine how about you]` is not a valid Python, so it's unclear what result you really expect. – Georgy Feb 03 '20 at 13:45

3 Answers3

1

You can use str.join(iterable) - method takes input iterable like list, string, etc. and return a string which is the concatenation of the strings in iterable.

>>> [' '.join(a)]
['Hi How are you i am doing fine how about you']
Dishin H Goyani
  • 7,195
  • 3
  • 26
  • 37
1

The following code does this:

result = " ".join(a)

Leonard
  • 783
  • 3
  • 22
0

In case you want to split the sentences further like the title suggests:

a = ['Hi How are you', 'i am doing fine', 'how about you']
words = [w for x in a for w in x.split()]
print(words)

Gives:

['Hi', 'How', 'are', 'you', 'i', 'am', 'doing', 'fine', 'how', 'about', 'you']

Using a nested list-comprehension

rdas
  • 20,604
  • 6
  • 33
  • 46