How to get all the words that start with a specific letter in Python

1 Answer

0 votes
words = ["python", "c", "c++", "java", "c#", "php", "nodejs", "javascript"]
 
letter = "c"

result = [w for w in words if w[0] == letter]

print(result)



'''
run:

['c', 'c++', 'c#']

'''

 



answered Jun 23, 2024 by avibootz
...