How to create a list out of the first letter of every word in a string with Python

2 Answers

0 votes
s = "python java c++ php vb.net"

words = s.split()

lst = []
for char in words:
    lst.append(char[0])

print(lst)



'''
run:

['p', 'j', 'c', 'p', 'v']

'''

 



answered Jul 18, 2019 by avibootz
0 votes
s = "python java c++ php vb.net"
 
words = s.split()
 
lst = [word[0] for word in words]
 
print(lst)
 
 
 
'''
run:
 
['p', 'j', 'c', 'p', 'v']
 
'''

 



answered Jul 18, 2019 by avibootz

Related questions

...