简体   繁体   中英

Extracting Dictionary Value from a Tuple

I have a tuple which is basically like this:

t=(OrderedDict([('attributes', OrderedDict([('type', 'User'), ('url', '/services/data/v38.0/sobjects/User/0006Cx6pIAC')])), ('Name', 'Ben Dams')]),)

How do I extract just the 'Name' from the dictionary?

You have a single-value tuple which contains a dictionary. So just use indexing before accessing a dictionary key:

res = t[0]['Name']  # 'Ben Dams'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM