How to find 3 letter words that start with specific letter in a string with Python

1 Answer

0 votes
s = "python java c++ php vb net ccg ct c qt ccc"
 
ch = 'c'
words = [word for word in s.split() if len(word) == 3 and word[0].lower() == ch.lower()]
 
print(words)
 
 
 
'''
run:
 
['c++', 'ccg', 'ccc']
 
'''

 



answered Jul 18, 2019 by avibootz
...