Hey! How do I use split() to get words from a text file? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Hey! How do I use split() to get words from a text file?

Tuple

20th Oct 2021, 6:57 PM
Olivia Matinlauri
3 Answers
+ 3
You get the text from the file and split like so. words = text.split()
20th Oct 2021, 7:04 PM
Slick
Slick - avatar
+ 2
Please always tag the language you're asking about. https://code.sololearn.com/W3uiji9X28C1/?ref=app
20th Oct 2021, 7:24 PM
Simon Sauter
Simon Sauter - avatar
+ 1
with open('file patht','r') as f: for line in f: for word in line.split(): print(word) f.close()
20th Oct 2021, 7:08 PM
ubai
ubai - avatar