how to safely extract dict values

Bruno Desthuilliers onurb at xiludom.gro
Mon Jul 31 07:30:30 EDT 2006


David Zaret wrote:
> thanks for the many responses.
> 
> i have zero control over the dict.  in practice, i'm using turbogears
> which is "automatically" populating the result dict with zero-to-many
> choices from a generated list of HTML checkboxes.  the user can select
> none, one, or many, and submit.  cherrypy packs the **kwargs arg full of
> the selection, as i described in my op.

Are you sure you get mydict[mykey]==None if the user doesn't check any
of the checkboxes ? According to html specs, the form's dataset
shouldn't  have the key at all in this case.

> using a try/exception case to switch between append and extend will not
> work.  

Nope.

> the scalar, coming back as a string, can certainly be iterated
> and i'll end up with a bunch of characters in my list.

Yes.

> i like what's posted below 

Thanks - and BTW, please, don't top-post...

-- 
bruno desthuilliers
python -c "print '@'.join(['.'.join([w[::-1] for w in p.split('.')]) for
p in 'onurb at xiludom.gro'.split('@')])"



More information about the Python-list mailing list