remove item from list based on name

Larry Bates lbates at swamisoft.com
Thu May 27 17:05:23 EDT 2004


I'm glad they worked for you.

I tend to stay away from V2.3 "only" solutions, but
I guess it's probably time I started recommending
using these new features.

-Larry
"Bart Nessux" <bart_nessux at hotmail.com> wrote in message
news:40B64C36.5030600 at hotmail.com...
> Thanks Peter & Larry,
>
> Both of the examples work (lists and sets). I had forgotten that I had
> done something similar in the past with both functions. I find the set
> approach cleaner, but both approaches get the job done.
>
> Thanks Again!
>
>
> Peter Otten wrote:
> > Bart Nessux wrote:
> >
> >
> >>I am generating a list of file names... some of the files are locked by
> >>the OS (Windows XP) and I know the names of these files (NTUSER.DAT,
> >>ntuser.dat.LOG, etc.) But, I don't know their position in the list. Is
> >>there a way that I can delete these items from the list based on their
> >>names?
> >
> >
> >>>>from sets import Set
> >>>>list(Set(["a", "b", "c"]) - Set(["c", "d"]))
> >
> > ['a', 'b']
> >
> > Remember to pass all filenames through os.path.normcase() before trying
the
> > above.
> >
> > Peter
>





More information about the Python-list mailing list