python中字典套字典的读取

eg:

d = {0:{"language":["Python", "Go"]},"coder":{"person":["life", "more"]}}

print(d[0]["language"])

print(d["coder"]["person"])

output:

['Python', 'Go']
['life', 'more'] 

users = {

    'aeinstein':{

        'first':'albert',

        'last':'einstein',

        'location':'princeton',

    },

    'mcurie':{

        'first':'marie',

        'last':'curie',

        'location':'paris',

    },

}

for username,user_info in users.items():

    print("\nUsername:" + username)

    full_name = user_info['first'] + ''+ user_info['last']

    location  = user_info['location']

    print("\tFull name :" + full_name.title())

    print("\tLocation  :" + location.title())

output:

Username:aeinstein
        Full name :Alberteinstein
        Location  :Princeton

Username:mcurie
        Full name :Mariecurie
        Location  :Paris

 

你可能感兴趣的:(Python,python,开发语言,后端)