Given a Sentence, write a Python program to convert the given sentence into list of words.
Input : ['Hello World'] Output : ['Hello', 'world'] Input : ['Geeks For geeks'] Output : ['Geeks', 'for', 'geeks']
The simplest approach provided by Python to convert the given list of Sentence into words with separate indices is to use
split() method. This method split a string into a list where each word is a list item. We have alternative ways to use this function in order to achive the required output.
Method #1 : Splitting the first index element
['Geeks', 'For', 'geeks']
Method #2 : Using for loop
We can also use a for loop to split the first element. This method is also beneficial if we have more than one element.
['Geeksforgeeks', 'is', 'a', 'portal', 'for', 'geeks']
Method #3 : Using
We can split the given list and than join using
join() function. We can also use this when you have a list of string or single string inside a list.
['Hello', 'Geeks', 'for', 'geeks']
- Python | Ways to Spilt the list by some value
- Python | Check if given words appear together in a list of sentence
- Python | Remove all duplicates words from a given sentence
- Python | Sort words of sentence in ascending order
- Python program to count words in a sentence
- NLP | How tokenizing text, sentence, words works
- Python | Joining only adjacent words in list
- Python | Find k longest words in given list
- Python - Remove words containing list characters
- Python - Remove duplicate words from Strings in List
- Python | Extract Nth words in Strings List
- Python - Extract words starting with K in String List
- Python - List Words Frequency in String
- Python Program that Extract words starting with Vowel From A list
- Python | Convert a nested list into a flat list
- Python | Convert a string representation of list into list
- Python | Convert list of string into sorted list of integer
- Python | Convert list of tuples into list
- Python | Convert given list into nested list
- Python | Convert list into list of lists
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.