0
How do I access the first letter of every word in a string in python?
10 Respostas
+ 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.