0

Title Encoder

file = open("/usercode/files/books.txt", "r") books = file.readlines() print("\n".join(["".join([words[0] for words in book.split()]) for book in books])) file.close() Pls who can help me write an expanded form of what is inside the print function?

2nd Jun 2022, 3:29 PM
Oluwadurotimi Efunshile
10 ответов
+ 2
Oluwadurotimi Efunshile , we are missing the task description, and also the name of the python tutorial and exercise number
2nd Jun 2022, 6:40 PM
Lothar
Lothar - avatar
+ 2
Oluwadurotimi Efunshile , not sure if this is what you wanted to see. i have put comments to the code. file = open("books.txt", "r") books = file.readlines() for book in books: # outer loop to get each line of the txt file tmp = [] # buffer list that is used to collect the first letter of each word for word in book.split(): # inner loop to split each line to individual words tmp.append(word[0]) # take each individual word, get the first letter and store it in list print("".join(tmp)) # print the collected letters from each line file.close()
4th Jun 2022, 10:12 AM
Lothar
Lothar - avatar
+ 1
Lothar the Last module of intermediate python.
2nd Jun 2022, 9:07 PM
Oluwadurotimi Efunshile
0
What do you mean by expanded form?
2nd Jun 2022, 4:02 PM
Justice
Justice - avatar
0
Help me to represent each statement with letters one by one Something like: for book in books: .... ... ... print("\n".join...) file.close()
2nd Jun 2022, 4:14 PM
Oluwadurotimi Efunshile
0
Instead of everything on one line inside the print statement
2nd Jun 2022, 4:15 PM
Oluwadurotimi Efunshile
0
#it can be expanded like the following: file = open("/usercode/files/books.txt", "r") books = file.readlines() for book in books: for words in book.split(): print(words[0],end="") print() file.close()
2nd Jun 2022, 8:54 PM
Sousou
Sousou - avatar
0
It's the expanded form using the join function that I actually want to get
2nd Jun 2022, 9:03 PM
Oluwadurotimi Efunshile
0
Sousou it's actually the expanded form, using the join function that I want to get
2nd Jun 2022, 9:06 PM
Oluwadurotimi Efunshile
0
Lothar thanks so much
4th Jun 2022, 10:44 AM
Oluwadurotimi Efunshile