-4

Given a variable , state_capitals , that refers to a dictionary that maps U.S. states to their capitals, and another dictionary, provincial_capitals , that maps Canadian provinces to their capitals, associate a dictionary that maps states or provinces to their respective capitals with a variable , regional_capitals .

this what I have so far:

{provincial_capitals.keys} + (state_capitals.keys) == regional_capitals

user3577692
  • 1
  • 1
  • 4
  • 1
    possible duplicate of [How can I merge (union) two Python dictionaries in a single expression?](http://stackoverflow.com/questions/38987/how-can-i-merge-union-two-python-dictionaries-in-a-single-expression) – Daniel Rucci Apr 28 '14 at 19:58
  • 1
    So what does your code so far *do*? – jonrsharpe Apr 28 '14 at 20:00
  • 1
    BTW, "==" is for testing conditionals, not for setting something equal to something else. – mauve Apr 28 '14 at 20:05
  • @user3577692 to answer my own question, your current "code" attempts to make a set of an instance method (not even the output from the method), tries to add that to the same method for another instance, then compares the result for equality to a variable you probably haven't defined yet. What did you expect it to do? I suggest you find an introductory python tutorial and work through it. – jonrsharpe Apr 28 '14 at 20:26
  • Hiya, to make your question a little bit more likely to be answered, I'd also include what the output of your current code-attempt is, and what you'd expect the output to say... also I'd have a go with a couple of tiny sets of data (eg create those variables as just tiny sets of only two capitals, and try the code you've got above and see what the output is). – Taryn East May 07 '14 at 03:09

1 Answers1

3

I think you're looking for the dict.update() method:

regional_capitals = {}
regional_capitals.update(state_capitals)
regional_capitals.update(provincial_capitals)
Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485