[Tutor] Removing Null Elements from a List

Jörg Wölke lumbricus@gmx.net
Sat, 10 Mar 2001 09:19:22 +0100 (MET)


> If I have a list that looks like:
> 
> [None, None, None, None, None, None, None, None, None, None, 
> ['/atl/horseradishgrill_1'], None, None, None, None, None, None, None,
> None, 
> None, None, None, None, None, None, None, None, None, None, 
> ['/boston/archive'], None, None, None, ['/boston/cafe_fleuri'], None,
> None, 
> None, None, None, None, None, None, None, None, ['/boston/rplace'], 
> ['/boston/salamander'], None, ['/boston/test'],
> ['/boston/the_federalist'], 
> None, ['/boston/yanks']]
> 
> How can I remove those None elements in it? The code that I'm getting that
> 
> >from is, in part, this:
> 
>     chosen = []
>     badFiles = []
> 
> 
>     pick = re.compile(theDate)
>     for elements in files:
>         if pick.search(elements):
>             chosen.append(elements)
>             #print chosen
> 
>     if chosen == []:
>         #print ftp.pwd()
>         badFiles.append(ftp.pwd() )
>         return badFiles
> 

if <your function> is not None:
	list.append(<your function>)

> Basically, if a directory listing from an FTP site does *not* have a file 
> with today's date on it, it should be added to the list badFiles. Since
> some 
> directories are fine, they're being added as None. How can I either stop 
> this, or just remove them from the final list. Either solution would work 
> just as well for me.
>

result=[]
for item in list:
	if item is not None:
		result.append item

 
> Thanks for the continued help. I appreciate it.
> 
> Britt
> _________________________________________________________________
> Get your FREE download of MSN Explorer at http://explorer.msn.com
> 
> 
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
> 

Grreetings Jö!

-- 
Sent through GMX FreeMail - http://www.gmx.net