0

How do I access the first letter of every word in a string in python?

2nd Jul 2020, 11:36 AM
Lucas Biiyiin
Lucas Biiyiin - avatar
10 Answers
+ 7
Lucas Biiyiin, before you ask for help, you should do a try by yourself, put it in playground and post it here. Thanks!
2nd Jul 2020, 12:00 PM
Lothar
Lothar - avatar
+ 7
PrOCOd3r, the question was: How do I access the first letter >>of every word in a string<< in python? The sample you posted here does not fit to the requirements of the question. It just outputs the first letter of the complete string. To get it done, correctly, the string has to be split() before using an iteration.
2nd Jul 2020, 1:54 PM
Lothar
Lothar - avatar
+ 3
s = "this is a string" for c in s.split(): print(c[:1])
2nd Jul 2020, 11:55 AM
♡Addy♡
♡Addy♡ - avatar
+ 3
Lothar oh, i’m sorry. i accidentally read the question wrong, i’m sorry
2nd Jul 2020, 2:51 PM
Pr0C0d3r
Pr0C0d3r - avatar
3rd Jul 2020, 7:11 AM
Matvey Anoshin
Matvey Anoshin - avatar
0
c=“this is a string” c=c.split() for i in range(0,len(c)): print(c[i][0])
4th Jul 2020, 5:46 AM
Pr0C0d3r
Pr0C0d3r - avatar
- 1
c=“this is a string” print(c[0]) edit: i got thsi wrong sorry about that, but i’ll post another right answer.
2nd Jul 2020, 12:09 PM
Pr0C0d3r
Pr0C0d3r - avatar