Extract all words that begin with x
Jimbo
nilly16 at yahoo.com
Mon May 10 04:40:05 EDT 2010
Hello
I am trying to find if there is a string OR list function that will
search a list of strings for all the strings that start with 'a' &
return a new list containing all the strings that started with 'a'.
I have had a search of Python site & I could not find what I am
looking for, does a function like this exist?
The only one that I think could work is, use the string
function .count()
algorithm: to exract all the words inside a list that start with 'a'
- make sure the list is arranged in alphabetical order
- convert the list to a big string
- use list_string.count(',a') to obtain the index where the last 'a'
word occurs
- convert back into string (yes this is a REAL hack :P)
- and then create a new list, ie, new_list = list[0:32]
- & return new_list
Ok that algorithm is terrible, I know, & I just realise that it wont
work for letters after 'a'. So if anyone could suggest a function or
algorithm it would be extremely helpful
More information about the Python-list
mailing list