I have a list that contains several tuples, like:
[('a_key', 'a value'), ('another_key', 'another value')]
where the first tuple-values act as dictionary-keys. I’m now searching for a python-like way to access the key/value-pairs, like:
'mylist.a_key' or 'mylist['a_key']'
without iterating over the list. any ideas?
You can’t do it without any iteration. You will either need iteration to convert it into a dict, at which point key access will become possible sans iteration, or you will need to iterate over it for each key access. Converting to a dict seems the better idea– in the long run it is more efficient, but more importantly, it represents how you actually see this data structure– as pairs of keys and values.