data=[{"name":"Instagram",'follower_count':346,"description":"社交媒体平台","country":"United States"},{"name":"Cristiano Ronaldo",'follower_count':215,"description":"Footballer","country":"Portugal"},{"name":"Ariana Grande",'follower_count':183,"description":"音乐家和演员","country":"United States"}]
def dictionary_value((:
用于数据中的值:返回值["name"],值["follower_count"],值["description"],取值["country"]
嗨,我是python的新手,我有一个关于字典和列表的问题:我希望我的函数字典value((只返回值,并按列表中的位置打印函数,例如:如果我想选择数据[2],结果应该是:"Ariana Grande",183,"Musician and Actor","United States"。我找不到办法。
使用dict.values
方法:
def dictionary_value(i):
return list(data[i].values())
输出:
print(dictionary_value(2))
# 'Ariana Grande', 183,'Musician and actress','United States'