Can anyone explain how this code works? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Can anyone explain how this code works?

file = open("/usercode/files/books.txt", "r") #your code goes here var = file.readlines() for name in var: l = list(name.split(' ')) s = "" for i in l: s += i[0] print(s) file.close()

15th Feb 2021, 12:19 PM
ekkwnsnsnwkkqwknnq
ekkwnsnsnwkkqwknnq - avatar
1 Answer
+ 2
1. Iterates each line (each book title) of the file 2. Separates and Iterates each word of the book title 3. Get the first character of each word 4. Add those first character to 's' 5. Prints the 's' Output: ---> Initials of each word each Book titles Explanation inside 👇 https://code.sololearn.com/cED0N2c19xI9/?ref=app
15th Feb 2021, 12:25 PM
noteve
noteve - avatar