Add two dicts

Afanasiy abelikov72 at hotmail.com
Fri Aug 29 00:11:09 EDT 2003


I have some code like this...

  self.write(
    '''
    lots of stuff here with %(these)s named expressions
    '''
    % vars(self)
  )

Then I wanted to add an item to the dict vars(self), so I tried :

  vars(self)+{'x':'123','y':'345'}

This doesn't work, perhaps because no one could decide what should happen
to keys which already exist in the dict? (I'd say throw an exception).

Can I add two dicts in a way which is not cumbersome to the above % string
operation? Is this another case of writing my own function, or does a
builtin (or similar) already exist for this?





More information about the Python-list mailing list