0
(Solved)Hallo, I'm stuck with title encoder. How to get initial of book's title, example Harry Potter is 'HP'. Give me advice
I don't ask the code, but where my mistake is, thank you. file = open("/usercode/files/books.txt", "r") #your code goes here for i in file : for j in i.split(): a.append(j[0]) print(a) file.close()
6 Respostas
+ 1
You don't need the nested loop nor do you need to split() the line from the file.
Loop over each line of the file and output only the first character of the line concatenated to the length of the line (not including trailing whitespace, '\n')
You can get the first character using the index 0 and the length by passing the str.strip() to the len function.
Example;
line = "Harry Potter and the Sorcerer's Stone\n"
first_letter = line[0] # 'H'
line_length = len(line.strip()) # 37
0
No, not getting initial then the Len but the first char from each word
0
My code works for 1 line but, more than one not
0
Is this for the;
52 end of module project
'Book Titles'
in the core python course?
0
No, intermediate Python
0
Ahhh, ok, sorry thought it was a different module project. Well looks like you got it figured out anyhow.