On Sep 5, 10:00 pm, Sreeraj <[EMAIL PROTECTED]> wrote: > hi, > > I am a beginner in Python. I wish to know how can i filter a list of > strings using wild characters.ie > Lets say i have list countries = > ["india","africa","atlanta","artica","nigeria"]. I need only the list > of string starting with 'a'. > > thank you > > Sreeraj
The most thorough answer would no doubt involve regular expressions, but they can be unpleasant. To do a "string*" type wildcard filter as in your request: myList = ["india","africa","atlanta","artica","nigeria"] newList = [ item for item in myList if item.startswith("a") ] To do a "*string" wildcard filter use the endswith() function instead of startswith() and to do a *string* type wildcard filter use the find() function > -1. -- http://mail.python.org/mailman/listinfo/python-list