0
please explain this code how it's work
file = open("/usercode/files/books.txt", "r") for title in file: for word in title.split(): print(word[0], end="") print() #your code goes here file.close()
5 Réponses
+ 2
Jayakrishna🇮🇳 Lothar thanks
+ 7
Sojib M ,
just to add one comment to the post of Jayakrishna🇮🇳 :
...
print(word[0], end="") # print only the first character 'word[0]' of each splited word, but print them all in the same line
...
+ 3
file = open("/usercode/files/books.txt", "r") # open file in read mode..
for title in file: # for each line from file
for word in title.split(): # split by space, each line into words
print(word[0], end="") # print the split words first (edit:) character only, with in same line.
print() # print line break
#your code goes here
file.close() # close opened file
# hope it helps.....
+ 1
Oh. I have a typo mistake in 'first, it's not for'.
[ first character only . not for character only ]
+ 1
its printing the first character of each word in the title.. For example..."Here is the title" gives "Hitt".