[Tutor] argparse iterable

kendy at kendy.org kendy at kendy.org
Tue Apr 2 21:24:41 CEST 2013


I forgot about update. It's nice and clean:

     a.update(b)

However, when 'a' has values and 'b' is None, the 'a' item gets clobbered with
None. I found this on stackoverflow.com:

------------------
old = {1: 'one', 2: 'two'}
new = {1: 'newone', 2: None, 3: 'new'}
old.update( (k,v) for k,v in new.iteritems() if v is not None)
------------------

Exactly what I need.

Thanks for the update hint!
Ken

On Tue Apr  2  2:50 , Dave Angel  sent:

>On 04/01/2013 10:28 PM, kendy at kendy.org wrote:
>> You guys are awesome! You make it look easy and I learn every time.
>>
>
>Once you've got the two dicts, take a look into the update method.  It 
>may make any loops unnecessary, except for debugging.
>
>
>-- 
>DaveA
>_______________________________________________
>Tutor maillist  -  Tutor at python.org
>To unsubscribe or change subscription options:
>http://mail.python.org/mailman/listinfo/tutor




More information about the Tutor mailing list