Skip to content
Advertisement

Access data in python3 associative arrays

I’d like how to create and print associative arrays in python3… like in bash I do:

JavaScript

In bash I can do echo "${array["beta",1]}" to access data to print “text2”.

How can I define a similar array in python3 and how to access to data in a similar way? I tried some approaches, but none worked.

Stuff like this:

JavaScript

But I can’t access to data with print(array['beta', 1]). It is not printing “text2” :(

Advertisement

Answer

It looks like you want a dictionary with compound keys:

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