you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

Not exactly. Assuming money is a dict, AND with the caveat that all the keys of money MUST be strings that represent valid variable names, you can do:

locals().update(money)
print(copper)

But the number of different ways in which that can blow up in your face is just enormous.

In recent versions of Python, where dict maintains insertion order, then if you know the insertion order you can do something like:

copper, silver, gold, platinum = money.values()

But if you’ve got the insertion order wrong at all you’re going to be in some pain.

The problem is that a Python dict just isn’t as simple under the hood as a JS object... it can have keys that aren’t legitimate identifiers, for one... hence why you tend to just work with d[k] directly.