remove item from list based on name

Bart Nessux bart_nessux at hotmail.com
Thu May 27 16:14:46 EDT 2004


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