Skip to content
Advertisement

I can’t do anything with python dict? [closed]

Im really stuck with a little problem that I have.

JavaScript

Currency_price.json is a file which contains a dictionary like this:

JavaScript

With the key being the currency and the value a list with its prices.

My problem is that after I pass all the info to diccionario_antiguos, I can’t manipulate anything inside it.

if i do for instance:

JavaScript

I get ‘str’ object has no attribute ‘get’

If I do

JavaScript

I get string indices must be integers

And then I said “Oh, I should have tu use integers”, so I did:

JavaScript

No Exception there, but I get [] (when I printed the whole dictionary and I KNOW the data IS there).

I don’t know what’s happening, because if I apply this methods with any dictionary, they’ll work, even if the key is a String.

Any solutions? Thank you!

Advertisement

Answer

Here is code for json and dict…

JavaScript

output

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement