No subject

Shane Geiger sgeiger at ncee.net
Sat Mar 17 05:41:03 EDT 2007


Milton,

This isn't terribly elegant, but it gets the job done:

dirs = ['C:\Images', 'C:\Images\2006', 'C:\Images\2007', 'C:\Music', 
'C:\Files', 'C:\Software', 'C:\Software\Python', 'C:\Software\iTunes']     

exclude_list = 
['Software','Images']                                                                                                             


def foo(d):
    retval = d
    for item in exclude_list:
        if item in d:
            retval = False
    return retval

dirs = map(foo, dirs)
dirs = filter(bool, dirs)  # removes the Falses
print dirs


Milton Segura wrote:
> Hello, I'm trying to exclude files from a list using the following code:
>  
> for item in dirs:
>     if item.find('Software') > -1:
>         dirs.remove(item)
>     elif item.find('Images') > -1:
>         dirs.remove(item)
>  
> let's supose dirs = ['C:\Images', 'C:\Images\2006', 'C:\Images\2007', 
> 'C:\Music', 'C:\Files', 'C:\Software', 'C:\Software\Python', 
> 'C:\Software\iTunes']
>  
> For some reason.. it just won't exclude them.
> I'd like to know why and how to fix it.
> Thanks in advance.
> Milton
>
> ------------------------------------------------------------------------
> Explore the seven wonders of the world Learn more! 
> <http://search.msn.com/results.aspx?q=7+wonders+world&mkt=en-US&form=QBRE>

-- 
Shane Geiger
IT Director
National Council on Economic Education
sgeiger at ncee.net  |  402-438-8958  |  http://www.ncee.net

Leading the Campaign for Economic and Financial Literacy

-------------- next part --------------
A non-text attachment was scrubbed...
Name: sgeiger.vcf
Type: text/x-vcard
Size: 310 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20070317/0851ae43/attachment.vcf>


More information about the Python-list mailing list