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

17th Apr 2019, 6:13 AM
Prashant Pokhriyal
Prashant Pokhriyal - avatar
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()
17th Apr 2019, 6:37 AM
Dima Makieiev
Dima Makieiev - avatar
17th Apr 2019, 6:47 AM
Yugabdh
Yugabdh - avatar