-2

I have this list:

["This is a set of words and it is not correct"]

I want to make it like this:

["This", "Is", "A"] ...

How do I do this

nu11p01n73R
  • 26,397
  • 3
  • 39
  • 52
ProCode
  • 9
  • 1
  • 2

3 Answers3

3
"This is a set of words and it is not correct".title().split()

output:

['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct']
khelili miliana
  • 3,730
  • 2
  • 15
  • 28
1

You can do like this.

a = "This is a set of words and it is not correct"
[i.capitalize() for i in a.split()]

if input is list as you mentioned in your question.

a = ["This is a set of words and it is not correct"]
[i.capitalize() for i in a[0].split()]

Output

['This', 'Is', 'A', 'Set', 'Of', 'Words', 'And', 'It', 'Is', 'Not', 'Correct']

Rahul K P
  • 15,740
  • 4
  • 35
  • 52
0

Use the split() method

>>> foo = ["This is a set of words and it is not correct"]
>>> foo[0].split()
['This', 'is', 'a', 'set', 'of', 'words', 'and', 'it', 'is', 'not', 'correct']
Bernardo Meurer
  • 2,295
  • 5
  • 31
  • 52