I'm pretty new to Python programming and I have gotten stuck on how to return the data in a function in reverse.
For example, if data.txt contains:
Chaos reigns within.
Reflect, repent, and reboot
Order will return.
A call to write_reversed('data.txt') will print:
Order will return.
Reflect, repent, and reboot
Chaos reigns within.
The code I have currently written is
def write_reversed(filename):
"""returns with words in reverse order in the file"""
with open(filename, 'r') as write_reversed:
for line in write_reversed:
return filename[::-1]
I have pasted my code into a Pylint checker and it says "unused variable 'line'"