+ 1
Write a code to reverse the each line of a given file 🙏
note:we shouldn't use any inbuilt functions to reverse the strings
3 Respostas
+ 4
infile=open("file.txt","r")
a=list(map(lambda x:x[::-1],infile.readlines()))
infile.close()
outfile=open("newfile","w")
outfile.write("\n".join(a))
outfile.close()
+ 2
#my code in Python
l=[ ]
i=0
a=int(input("Enter The Size:"))
while(i<a):
l.append(int(input("enter elements")))
i=i+1
def reverse(l):
r=[ ]
c=len(l)
while(c>=1):
r.append(l[c-1])
c=c-1
print("the reversed list is:",r)
reverse(l)
+ 2
#in Python
f = open("text.txt", "rb")
s = f.read()
f.close()
f = open("newtext.txt", "wb")
f.write(s[::-1])
f.close()