I'm unable to determine an easy way to have a list with values assigned to each item in the list, where when an item is called the value will be printed.
I've tried to use tuples in a list, such as foo = [('bar', 1), ('baz', 2)]
, and then calling foo[1]
, but instead of doing 2
, it goes ('baz', 2)
.
>>> foo = [('bar', 1), ('baz', 2)]`
>>> foo[1]
or
>>> foo[1[1]]
Neither seems to work. The former calling method emits (baz, 2)
and the latter produces an error.
Is there a different way to do this? Or is this correct, but I'm doing something wrong?