Reputation: 39
Suppose this is a dictionary : {'name': 'Instagram', 'follower_count': 346, 'description': 'Social media platform', 'country': 'United States'}
and i want my output like : Instagram, Social media platform, United States
How do I achieve this?
Upvotes: 0
Views: 67
Reputation: 34
Use the key in condition to whatever value you want to eliminate
for i in thisdict:
if i == "follower_count":
continue
else:
print(thisdict[i])
Or you may also use .items method to get key,values and then continue
for k,v in thisdict.items():
if k=="follower_count":
continue
else:
print(v)
Upvotes: 0
Reputation: 477
This is the simplest way you can get what you want:
dct = {
'name': 'Instagram',
'follower_count': 346,
'description': 'Social media platform',
'country': 'United States'
}
print(f'{dct['name']}, {dct['description']}, {dct['country']}')
Output:
Instagram, Social media platform, United States
Upvotes: 0
Reputation: 4359
I think this is what you're looking for?
import operator
items_getter = operator.itemgetter('name', 'description', 'country')
print(', '.join(items_getter(dictionary)))
Upvotes: 2