Re: how to safely extract dict values

2006-07-31 Thread Amit Khemka
oops ! my mistake :-D On 7/31/06, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Amit Khemka wrote: > > how about: > > > > vals = [] > > for val in mydict.values(): > > try: vals.extend(val) > > except: vals.append(val) > > >>> l = [] > >>> l.extend((1, 2)) > >>> l > [1, 2] > >>> l.extend('a

Re: how to safely extract dict values

2006-07-31 Thread Bruno Desthuilliers
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 s

Re: how to safely extract dict values

2006-07-31 Thread Bruno Desthuilliers
Paul Rubin wrote: > Bruno Desthuilliers <[EMAIL PROTECTED]> writes: >> Too much useless lookup IMHO... > > Actually, you, me, and Amit all mis-read David's original exapmle. Actually, I plea not guilty - cf my answer to the OP !-) -- bruno desthuilliers python -c "print '@'.join(['.'.join([w[::

Re: how to safely extract dict values

2006-07-31 Thread David Zaret
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 *

Re: how to safely extract dict values

2006-07-31 Thread Bruno Desthuilliers
Amit Khemka wrote: > On 7/31/06, David Zaret <[EMAIL PROTECTED]> wrote: >> i have a dict with a particular key - the values for this key will be >> None, one valid scalar, or a list: >> >> {mykey, None} >> {mykey, "foo"} >> {mykey, ["bar", "baz"]} >> >> let's ignore the None

Re: how to safely extract dict values

2006-07-31 Thread Paul Rubin
Bruno Desthuilliers <[EMAIL PROTECTED]> writes: > Too much useless lookup IMHO... Actually, you, me, and Amit all mis-read David's original exapmle. What he really wanted was (let's see if I get it right this time): if mykey in mydict: v = mydict[mykey] if not isinstance(v, list):

Re: how to safely extract dict values

2006-07-31 Thread Bruno Desthuilliers
David Zaret wrote: > i have a dict with a particular key - the values for this key will be > None, one valid scalar, or a list: > > {mykey, None} > {mykey, "foo"} > {mykey, ["bar", "baz"]} > > let's ignore the None case - in the case of the one or many values, i > want to suck the val

Re: how to safely extract dict values

2006-07-31 Thread Amit Khemka
On 7/31/06, David Zaret <[EMAIL PROTECTED]> wrote: > i have a dict with a particular key - the values for this key will be > None, one valid scalar, or a list: > > {mykey, None} > {mykey, "foo"} > {mykey, ["bar", "baz"]} > > let's ignore the None case - in the case of the on

Re: how to safely extract dict values

2006-07-31 Thread Bruno Desthuilliers
Paul Rubin wrote: > David Zaret <[EMAIL PROTECTED]> writes: >> my way is ugly. what's a better way? > > Untested: > > for key in mydict: >if isinstance(mydict[key], list): > vals.extend(mydict[key]) >else: > vals.append(mydict[key]) Too much useless looku

Re: how to safely extract dict values

2006-07-31 Thread Paul Rubin
David Zaret <[EMAIL PROTECTED]> writes: > my way is ugly. what's a better way? Untested: for key in mydict: if isinstance(mydict[key], list): vals.extend(mydict[key]) else: vals.append(mydict[key]) -- http://mail.python.org/mailman/listinfo/python-list

how to safely extract dict values

2006-07-31 Thread David Zaret
i have a dict with a particular key - the values for this key will be None, one valid scalar, or a list: {mykey, None} {mykey, "foo"} {mykey, ["bar", "baz"]} let's ignore the None case - in the case of the one or many values, i want to suck the values into a list. here'