I have the following data structure:
listionary = [{'a': [{'id': 30, 'name': 'bob'}, {'id': 50, 'name':'mike'}]},
{'b': [{'id': 99, 'name': 'guy'}, {'id': 77, 'name':'hal'}]}]
and I want to create a list of the values for each 'id' key.
ie. lst = [30, 50, 99, 77]
I know I need three iterators to traverse through the structure:
one to access the two parents dictionaries inside the array, another to access the lists of keys 'a' and 'b', and then a last to get the value of each id key in the nested child dictionaries
I tried
lst = [[x][y][y]['id'] for x, y, z in listionary]
but I got an error of
ValueError: not enough values to unpack (expected 3, got 1)
Is there a clean way to implement this?