Home > database >  how print the function by the location in the list?
how print the function by the location in the list?

Time:12-07

data = [ { 'name': 'Instagram', 'follower_count': 346, 'description': 'Social media platform', 'country': 'United States' }, { 'name': 'Cristiano Ronaldo', 'follower_count': 215, 'description': 'Footballer', 'country': 'Portugal' }, { 'name': 'Ariana Grande', 'follower_count': 183, 'description': 'Musician and actress', 'country': 'United States' }]

def dictionary_value():
for value in data: return value["name"], value["follower_count"],value["description"], value["country"]

Hi, I'm newbie in python and i have a question about dictionary and lists: i would like that my function dictionary value() will return only the values and print the function by the location in the list, for example: if i want to choose data[2] the outcome should be: 'Ariana Grande', 183,'Musician and actress','United States'. i could not find a way to do it.

CodePudding user response:

Use dict.values method:

def dictionary_value(i):
    return list(data[i].values())

Output:

print(dictionary_value(2))
# 'Ariana Grande', 183,'Musician and actress','United States'
  • Related