0
Python exercise from Sololearn
Dear all! I am requested to open a file that contains titles of books (1 in each row). I am then asked to print the first letter of the title plus the number of characters in it. For instance, The Great Gatsby gives as a result T16. Clearly, for all the titles but the last one I should not count the '\n' character. Did anybody find a solution? :) EDIT: file = open("mybooks", "r") Titles = file.read().split('\n') for title in Titles: print(title[0]+str(len(title)))
3 Antworten
+ 3
titles = file.read().split("\n")
# so titles is an array of lines without ending "\n"...
+ 2
Yes. So Many...
edit:
pls dont ask solution.. if you want , pls try it yourself first and post your try if unsolved. someone help you to correct it...
0
.strip('\n')