How to split a large sample of text into words in Python

0 votes

Hi Guys,

I have one large sample of text. I want to split this text into words. Can anyone tell me how can I do that?

Jun 26, 2020 in Python by akhtar
• 38,170 points
169 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use nltk module to split your text into words. I have attached one example below for your reference.

import nltk
word_data = "It originated from the idea that there are readers who prefer learning new skills from the comforts of their drawing rooms"
nltk_tokens = nltk.word_tokenize(word_data)
print (nltk_tokens)
['It', 'originated', 'from', 'the', 'idea', 'that', 'there', 'are', 'readers', 
'who', 'prefer', 'learning', 'new', 'skills', 'from', 'the',
'comforts', 'of', 'their', 'drawing', 'rooms']

I hope this will help you.

answered Jun 26, 2020 by MD
• 95,060 points

Related Questions In Python

0 votes
0 answers
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
2,165 views
0 votes
2 answers

How to calculate square root of a number in python?

calculate square root in python >>> import math ...READ MORE

answered Apr 2, 2019 in Python by anonymous
1,094 views
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 1,842 views
0 votes
0 answers
+4 votes
6 answers

Lowercase in Python

You can simply the built-in function in ...READ MORE

answered Apr 11, 2018 in Python by hemant
• 5,810 points
1,419 views
0 votes
1 answer

How to save one list in a text file in Python?

Hi@akhtar, There is no inbuilt function available to ...READ MORE

answered Jun 25, 2020 in Python by MD
• 95,060 points
196 views
0 votes
1 answer