0
How do I access the first letter of every word in a string in python?
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!
+ 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.
+ 3
s = "this is a string"
for c in s.split():
print(c[:1])
+ 3
Lothar
oh, iâm sorry. i accidentally read the question wrong, iâm sorry
0
c=âthis is a stringâ
c=c.split()
for i in range(0,len(c)):
print(c[i][0])
- 1
c=âthis is a stringâ
print(c[0])
edit: i got thsi wrong sorry about that, but iâll post another right answer.