![]() |
Accessing nested keys and values in Dictreader - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Homework (https://python-forum.io/forum-9.html) +--- Thread: Accessing nested keys and values in Dictreader (/thread-16615.html) |
Accessing nested keys and values in Dictreader - cartographer72 - Mar-07-2019 Hello, I'm using Dictreader to store a CSV with column headers in a container. I didn't have any issues bringing the CSV into the container, but I can't seem to grasp how to access the nested keys and values. From what I can tell, the 1st column is my primary key, but then subsequent column headers are also keys with values. I'm confused on how to retrieve a value from one of the sub-keys. For example, my primary key which I specified as a fieldname is called "Cars". I need to first find "Cars", then a second associated column (also a key)called "Model"...and then the associated value of "Model". Hopefully, that makes sense: Cars > Model > Value of Model. RE: Accessing nested keys and values in Dictreader - perfringo - Mar-07-2019 Something along those lines? >>> [row[“Model”] for row in my_dict if row[“Cars”] == “Tesla”] RE: Accessing nested keys and values in Dictreader - cartographer72 - Mar-08-2019 Thanks for the reply. I believe that's what I'm looking for. I'll give it shot. Much appreciated. |