On Mon, May 10, 2010 at 6:50 PM, Xavier Ho <cont...@xavierho.com> wrote:
> Have I missed something, or wouldn't this work just as well:
>
>>>> list_of_strings = ['2', 'awes', '3465sdg', 'dbsdf', 'asdgas']
>>>> [word for word in list_of_strings if word[0] == 'a']
> ['awes', 'asdgas']

I would do this for completeness (just in case):

>>>> [word for word in list_of_strings if word and word[0] == 'a']

Just guards against empty strings which may or may not be in the list.

--James
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to