Python: Printing a list from a txt file Need help trying to print a list from a
ID: 3706808 • Letter: P
Question
Python: Printing a list from a txt file
Need help trying to print a list from a txt file. Unfortunately, it's not a CSV.
The file is located here: http://www.filedropper.com/movies_1 or here http://s000.tinyupload.com/index.php?file_id=48953557772434487729
I need to display all of movie titles in order from the first column in the list (except the title line, first row) and on the last line display the number of movies listed.
Example output:
______________________
$
$1000 a Touchdown
$21 a Day Once a Month
. . .
Zzim
Zzyzx
Total number of movies: 58,000
_________________________________
This is my set-up, for the life of me, I can't ge the body of the syntax to work.
Explanation / Answer
Hi,
here is the full code with comments
import re
file = open("movies.txt", "r") #opening file
count=0
for line in file:#iterating file line by line
count=count+1 #counting lines
print(re.split(r'[ ]{2,}',line))#splitting with 2 or more space as delimiter
print(count)
Thumbs up if this was helpful, otherwise let me know in comments
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.