Reputation: 11
I am new to python.I want to know how to count the number of words starting with a particular letter say 'L' from a text file.
Upvotes: 0
Views: 1151
Reputation: 701
str.startswith(prefix[, start[, end]])
Give this a shot but import your file there are also a few other ways.
list = ["apple", "bannana", "custard", "shoe", "ant", "police", "python"]
newList = []
for word in list:
if word.startswith('a'):
newList.append(word)
print newList
['apple', 'ant']
Upvotes: 1