+ 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

18th Oct 2017, 3:13 PM
looper
looper - avatar
3 Answers
+ 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()
18th Oct 2017, 3:24 PM
👑 Prometheus 🇾🇬
👑 Prometheus 🇾🇬 - avatar
+ 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)
18th Oct 2017, 3:29 PM
Keerthana Vema
Keerthana Vema - avatar
+ 2
#in Python f = open("text.txt", "rb") s = f.read() f.close() f = open("newtext.txt", "wb") f.write(s[::-1]) f.close()
18th Oct 2017, 3:35 PM
Keerthana Vema
Keerthana Vema - avatar