0
How to solve this in easy way
5 Answers
+ 2
Mohammad Zakir ,
the code you have shown can be a bit simplified:
-> we don't need to use a list as a temporary buffer, after reading we can directly do the output
-> you can remove all lines that are marked with '#'
file = open("/usercode/files/books.txt", "r")
#Ist = []
for i in file:
#Ist.append(i.rstrip("\n"))
print(i[0]+str(len(i.rstrip())))
#for i in Ist:
#print(i[0]+str(len(i)))
file.close()
+ 1
How about you use the search bar?
0
Can't understand the book- tittle problem.....
Give me easy way to solve this..
0
Which
0
Try this way
with open("/usercode/files/books.txt", "r") as file:
contents = file.readlines()
for line in contents:
print(line[0]+str(len(line.strip())))