On files | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
- 1

On files

Pls guys I tried a code.....I wouldnt be able to post it ...but it was on files I was to pick the first letter in every line and join to the count of the words As in: F12 S11 F6 But when I did it I got stuffs like F 12 S 11 F 6 Pls can anyone help with how to remove the space in-between them so it looks like the first one . Thank you

8th Sep 2022, 8:11 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
7 Answers
+ 2
you dont print space 🤷🏻‍♂️ .. or post your code ...
8th Sep 2022, 8:18 AM
Prashanth Kumar
Prashanth Kumar - avatar
+ 2
Answer: print(line[0] + len(line))
8th Sep 2022, 4:21 PM
Ramtin Jafari
Ramtin Jafari - avatar
+ 1
E ~ J it there check it now
8th Sep 2022, 9:17 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
+ 1
And it actually printed it the problem is that it gave space between then eg F 12 But I wanted it to be F12 like this
8th Sep 2022, 9:18 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Prashanth Kumar file = open("/usercode/files/books.txt", "r") x=file.read().splitlines() file.seek(0) for line in x: print(line[0],len(line) )
8th Sep 2022, 8:26 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
E ~ J sorry I don't understand you
8th Sep 2022, 9:02 AM
Oyedeji Hiqmat
Oyedeji Hiqmat - avatar
0
Upload the code and let me put some comment and correction
10th Sep 2022, 9:56 AM
Emmanuel Odukoya
Emmanuel Odukoya - avatar