Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Dictionary list
#1
Create a list called menu, which should contain at least 4 items in the
cafe.
● Next, create a dictionary called stock, which should contain the stock
value for each item on your menu.
● Create another dictionary called price, which should contain the prices for
each item on your menu.
● Next, calculate the total stock worth in the cafe. You will need to
remember to loop through the appropriate dictionaries and lists to do
this.
● Finally, print out the result of your calculation.

Any idea on how to tackle this?
Reply
#2
By reading the instructions? Literally, it seems to tell you what to do. Surely you've learnt how to use the data structures, etc.? Otherwise, how did you rnd up with what looks like homework?
Reply
#3
(Sep-20-2020, 12:13 PM)ndc85430 Wrote: By reading the instructions? Literally, it seems to tell you what to do. Surely you've learnt how to use the data structures, etc.? Otherwise, how did you rnd up with what looks like homework?
Its creating 2 lists then convert them to a dictionary
Reply
#4
I don't know where you're getting "convert" from. I don't see anything about conversions in what you posted.

In any case, if you want help, you're going to need to show us what you've done.

There's also no need to quote the previous post in its entirety.
Reply
#5
menu = ['Burger','Cake','Sandwich','Tea']
price = ['32.55','22.80','15.45','10.20']
stock_dic = {key:value for key, value in zip(menu,price)}
print(stock_dic)

Reply
#6
Why are you storing prices as strings? What exactly are you having problems with?
Reply
#7
Okay am I in the right direction though.

menu = ['Burger','Cake','Sandwich','Tea']
price = [32.55,22.80,15.45,10.20]
stock_dic = {key:value for key, value in zip(menu,price)}
keys = stock_dic.keys()
values = stock_dic.values()
stock = 0
for i in stock_dic.values()
    stock += i

print(stock)
Reply
#8
You should have a dictionary named "price" that contains prices for each item. You should have a dictionary named "stock" that contains the stock value for each item. You should have a list called "menu" that is a list of all items. Hard code the dictionaries.

menu = ['Burger','Fries']
price = ['Burger':5.00, 'Fries':1.00]
stock = ['Burger':10, 'Fries':25]

The only time you iterate through menu is when calculating the total stock value.

Do what the assignment says, not what you think the assignment says. Try not to read anything into the problem description. If the assignment does not say "use the menu list to create a price dictionary" then don't do that.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Creating a dictionary from a list Inkanus 5 306 Nov-06-2020, 06:11 PM
Last Post: DeaD_EyE
  How to make a list of values from a dictionary list? faryad13 2 249 Sep-03-2020, 03:45 PM
Last Post: faryad13
  Issue accessing data from Dictionary/List in the right format LuisSatch 2 354 Jul-25-2020, 06:12 AM
Last Post: LuisSatch
  making list in looping a dictionary glennford49 9 661 Jun-25-2020, 03:23 PM
Last Post: ndc85430
  removing dictionary element in list using (key, value) MelonMusk 3 433 Jun-13-2020, 02:37 PM
Last Post: buran
  access dictionary with keys from another and write values to list redminote4dd 6 557 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Nested Dictionary/List tonybrown3 5 617 May-08-2020, 01:27 AM
Last Post: tonybrown3
  dot product of a list by a list in a dictionary stored as a value Fraher123 1 431 Mar-25-2020, 06:08 PM
Last Post: deanhystad
  Theory behind referencing a dictionary rather than copying it to a list sShadowSerpent 2 410 Mar-24-2020, 07:18 PM
Last Post: sShadowSerpent
  Dictionary and tuples list comprehensions help paul41 2 617 Nov-29-2019, 06:59 PM
Last Post: perfringo

Forum Jump:

User Panel Messages

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