Python Forum
Picking A number of items from a dict and getting there info
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Picking A number of items from a dict and getting there info
#1
What i want to do it take a certain number of foods and take them and there values and print the values out.


foods = {"Dempsters Whole Wheat Bread": {"cost":2.27, "calories": 1620, "Servings":18},
         "Dempsters White Bread": {"cost":2.27, "calories": 1620, "Servings":18},
         "Dempsters Everything Bagels": {"cost":2.98, "calories": 1200, "Servings":12},
         "Gala Apple": {"cost":0.71, "calories": 52, "Servings":1},
         "Clemintines": {"cost":2.97, "calories": 700, "Servings":20},
         "Great Value Egg": {"cost":2.27, "calories": 2080, "Servings":6},
         "Nelson Milk": {"cost":4.27, "calories": 1620, "Servings":16},
         "Great Value Cheddar Cheese": {"cost":4.97, "calories": 1800, "Servings":5},
         "Great Value Vanilla Yougurt": {"cost":1.77, "calories": 600, "Servings":7},
         "Great Value Orange Juice": {"cost":1, "calories": 440, "Servings":4}}
Reply
#2
Do you have any question?

Do you get any errors or the output is not correct? Show us your code, the errors ( properly - BBcode ).

We are willing to help but we will not do it for you.
"As they say in Mexico 'dosvidaniya'. That makes two vidaniyas."
https://freedns.afraid.org
Reply
#3
to access a food item, with food name as key:
food_item = foods['food name']
to access individual values in the selected item:
(used python 3.6 f-string
print(f'food_item: {food_item['cost']}')
To access all food items:
for item in foods.items():
    ...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Mediapipe. Not picking up second variable stevolution2024 1 162 Mar-31-2024, 05:56 PM
Last Post: stevolution2024
  What is all the info in the info window in Idle? Pedroski55 3 680 Jul-08-2023, 11:26 AM
Last Post: DeaD_EyE
  User input/picking from a list AnunnakiKungFu 2 2,319 Feb-27-2021, 12:10 AM
Last Post: BashBedlam
  Picking a function to execute palladium 1 1,595 Feb-09-2021, 04:47 PM
Last Post: deanhystad
  Count number of occurrences of list items in list of tuples t4keheart 1 2,364 Nov-03-2020, 05:37 AM
Last Post: deanhystad
  Print the number of items in a list on ubuntu terminal buttercup 2 1,931 Jul-24-2020, 01:46 PM
Last Post: ndc85430
  [regex] Good way to parse variable number of items? Winfried 4 2,600 May-15-2020, 01:54 PM
Last Post: Winfried
  Sort a dict in dict cherry_cherry 4 72,047 Apr-08-2020, 12:25 PM
Last Post: perfringo
  counting items in a list of number combinations Dixon 2 2,065 Feb-19-2020, 07:06 PM
Last Post: Dixon
  Count the number of items in a nested list iofhua 2 3,483 Jun-07-2019, 06:47 PM
Last Post: iofhua

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020