Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

extract specific key values from nested dictionary

>>> [val.get('phone') for val in people.values()]
['4563', '9102', '2341']
Comment

extract specific key values from nested dictionary

>>> [people[i]['phone'] for i in people]
['9102', '2341', '4563']
Comment

extract specific tuple values from two different keys from nested dictionary

print data.keys()                                                # top level keys
>>> ['alpha', 'beta']

print [x.keys() for x in data.values()]                          # second level keys
>>> [[9, 2, 3, 5], [9, 2, 3, 5]]

print [y.keys() for x in data.values() for y in x.values()]      # third level keys
>>> [[1, 3, 6], [1, 2], [1, 3, 6], [1, 3, 6], [1, 3, 6], [1, 2], [1, 3, 6], [1, 3, 6]]

print [y.values() for x in data.values() for y in x.values()]    # third level values
>>> [[9.0, 4.0, 5.5], [1.1, 4.1], [9.1, 4.1, 5.1], [9.2, 4.4, 5.4], [9.2, 4.9, 5.0], [4.0, 7.9], [24, 89, 98], [9, 4, 5]]
Comment

extract specific key values from nested dictionary

l = []
for person in people:
    l.append(people[person]['phone'])

>>> l
['9102', '2341', '4563']
Comment

PREVIOUS NEXT
Code Example
Python :: qt line edit set text python 
Python :: python check mognodb size 
Python :: extrapolate python 
Python :: micropython string to int 
Python :: how to wirte something 100 times with python 
Python :: python sha256 crypt decrypt 
Python :: concatenate dataframes using one column 
Python :: scrapy itemloader example 
Python :: What are zinc bandages used for? 
Python :: how to upload to PyPi with same name 
Python :: what is mi casa in spanish 
Python :: how to create a joystick in pyqt4 
Python :: staff user is not restricting permission in django 
Python :: scrapy get raw html content of selector innerhtml 
Python :: create a typo with python 
Python :: vertica long running queries 
Python :: python qt grid span 
Python :: access host database django docker 
Python :: sumx and ABS in power bi 
Python :: how to subtract numbers in python 
Python :: tf.slice 
Python :: Dateien mit modul requests herunterladen python 
Python :: Use if a not trusted message will come up 
Python :: ex: for stopping the while loop after 5 minute in python 
Python :: pandas difference between subsequent lines 
Python :: drop values based on type pandas 
Python :: datetime pypi 
Python :: Filter Top 5 Python 
Python :: merge namedtuple python 
Python :: Python Split list into chunks using itertools Method 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =