THis code is to remove words from a lists starting with a specified letter of the alphabet. The trouble is, is that it only removes some of the entries. when I run it to remove words beginning with 'a', only 'ana', 'agra', 'aba' are removed. Why? also is it possible to rewrite the condition to include a range of letters, say a-i for example?
def delete_from_list():
discarded=[]
#list_of_terms = pickle.load( open( "list_it.txt", "rb" ) )
list_of_terms = ['ana', 'agro','agra',' aaa','aba','bab','Banana', 'band', 'bink' ]
print('start length = ', len(list_of_terms))
for item in list_of_terms:
item.lower().strip()
if item.startswith('a'):
discarded.append(item)
list_of_terms.remove(item)
print('end_length = ', len(list_of_terms))
print(discarded, list_of_terms)
Thank you for your time and help.