Remove items from a list
Paul McGuire
ptmcg at austin.rr._bogus_.com
Wed Sep 8 01:15:08 EDT 2004
More information about the Python-list mailing list
Wed Sep 8 01:15:08 EDT 2004
- Previous message (by thread): Remove items from a list
- Next message (by thread): Remove items from a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
"Stan Cook" <scook at elp.rr.com> wrote in message news:yWv%c.33126$Dl4.19812 at fe2.texas.rr.com... > Yes, I used the listdir. The list is a list of files in the > directory. I want to filter everything out but the ".dbf" > files. > You said the answer yourself - "I want to _filter_ everything out but the ".dbf" files." Use filter built-in, and use str's endswith() method in place of [-4:] list slicing. dirlist = [ "a.txt", "b.txt", "c.dbf", "d.txt", "e.dbf" ] isdbf = lambda x : x.endswith(".dbf") print filter( isdbf, dirlist ) gives: ['c.dbf', 'e.dbf'] -- Paul
- Previous message (by thread): Remove items from a list
- Next message (by thread): Remove items from a list
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list