-1

I have a dictionary:

{'kind': 'identitytoolkit#GetAccountInfoResponse',
 'users': [{'createdAt': '1592641942167',
            'email': 'amer.99@gmail.com',
            'emailVerified': False,
            'lastLoginAt': '1592819446718',
            'lastRefreshAt': '2020-06-22T09:50:46.718Z',
            'localId': 'xHfdxJ2ALpQwscsoN2Pvf2GTH8E3',
            'passwordHash': 'UkVEQUNURUQ=',
            'passwordUpdatedAt': 1592641942167,
            'providerUserInfo': [{'email': 'amer.99@gmail.com',
                                  'federatedId': 'amer.99@gmail.com',
                                  'providerId': 'password',
                                  'rawId': 'amer.99@gmail.com'}],
            'validSince': '1592641942'}]}

I want to print the value for the 'emailVerified' key, so what do I have to do?

Georgy
  • 12,464
  • 7
  • 65
  • 73
Dimas
  • 11
  • 2

3 Answers3

2

Using pprint

from pprint import pprint

pprint({'kind': 'identitytoolkit#GetAccountInfoResponse', 'users': [{'localId': 
'xHfdxJ2ALpQwscsoN2Pvf2GTH8E3', 'email': 'amer.99@gmail.com', 'passwordHash': 'UkVEQUNURUQ=', 
'emailVerified': False, 'passwordUpdatedAt': 1592641942167, 'providerUserInfo': [{'providerId': 
'password', 'federatedId': 
'amer.99@gmail.com', 'email': 'amer.99@gmail.com', 'rawId': 'amer.99@gmail.com'}], 
'validSince': '1592641942', 'lastLoginAt': '1592819446718', 'createdAt': '1592641942167', 
'lastRefreshAt': '2020-06-22T09:50:46.718Z'}]})

-> Output:

{'kind': 'identitytoolkit#GetAccountInfoResponse',
 'users': [{'createdAt': '1592641942167',
            'email': 'amer.99@gmail.com',
            'emailVerified': False,
            'lastLoginAt': '1592819446718',
            'lastRefreshAt': '2020-06-22T09:50:46.718Z',
            'localId': 'xHfdxJ2ALpQwscsoN2Pvf2GTH8E3',
            'passwordHash': 'UkVEQUNURUQ=',
            'passwordUpdatedAt': 1592641942167,
            'providerUserInfo': [{'email': 'amer.99@gmail.com',
                                  'federatedId': 'amer.99@gmail.com',
                                  'providerId': 'password',
                                  'rawId': 'amer.99@gmail.com'}],
            'validSince': '1592641942'}]}

Here we can neatly see the structure: and the way to access the emailVerified is my_dict['users'][0]['emailVerified'] (where my_dict is just the name of the dict object)

leopardxpreload
  • 767
  • 5
  • 17
0

Assuming that is named 'sampleDict', you can read it like this

sampleDict['users'][0].get('emailVerified', False)

0 is the index of the list of users

'get' method takes two parameters

param1 is the key you wish to retrieve, param2 is the default value you wish to return if the key is not found.

0

You can refer to that value using dictionary["users"][0]["emailVerified"]

mrkubax10
  • 1
  • 2