0
How to read last word of a line in python
I have a text file with multiple lines,now I want to print the last word of the each line
2 odpowiedzi
+ 2
1) Read file line by line
2)split each line to list by space
3)print last element of each lines list
4) close file
file = open("file.txt", "r")
for line in file:
words = line.split(' ')
print(words[-1])
file.close()
+ 2
https://code.sololearn.com/ctGrbCqTQM1n/?ref=app
remove comments and try