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 | Check if given words appear together in a list of sentence
- Python | Ways to Spilt the list by some value
- Python program to count words in a sentence
- Python | Remove all duplicates words from a given sentence
- Python | Sort words of sentence in ascending order
- NLP | How tokenizing text, sentence, words works
- Python | Joining only adjacent words in list
- Python | Find k longest words in given list
- Python | Reverse each word in a sentence
- Possible Words using given characters in Python
- Reverse words in a given String in Python
- Python | Stemming words with NLTK
- Python | Extract words from given string
- Python | Scramble words from a text file
- Removing stop words with NLTK in Python
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.