0

I have a dictionary in program A where I want program B to add new contents into. Is this something I can accomplish? I tried googling but it was all about appending a dictionary within the same code, and I really want to be able to do it from within a different program if at all possible.

I am trying to add entries to a dictionary which contains {user : password, user2 : password2} for any new users. This is not to be registered to as only an admin should be able to add users. This is where the other program idea came into play. But I am open to any solution!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
  • 2
    This sounds suspiciously like an [XY problem](http://meta.stackexchange.com/questions/66377/what-is-the-xy-problem). – Phylogenesis Mar 27 '15 at 09:13
  • Possible duplicate of: [Python append dictionary](http://stackoverflow.com/questions/8930915/python-append-dictionary-to-dictionary) – Static Mar 27 '15 at 09:17

1 Answers1

0

If you want to achieve this using functions, you can use the dict.update function.

def combine_dicts(x, y):
    x.update(y)
    return x

def get_passwords():
    dict = {"a":"test", "b":"testa"}
    return dict

firstDict = {"this":"is", "a":"test"}
secondDict = get_passwords()
combinedDict = combine_dicts(firstDict, secondDict)

Note: The parameter you use of dict.update() will override existing value/key pairs.

Static
  • 193
  • 1
  • 1
  • 10