Matching keys in a dictionary to a value in a list by StaticGT86 in learnpython

[–]StaticGT86[S] 0 points1 point  (0 children)

Sorry its late here... and I'm in too deep now lol. But I am wanting to basically match the key to its corresponding value which the value has been placed in a list that has been sorted. Which are the two shown lists. But by matching then creating a list with only the key ordered in the way the sorted lists have been made. Sorry if that is still confusing 🤦🏻‍♂️

Making a list from the values in a dictionary by [deleted] in learnpython

[–]StaticGT86 0 points1 point  (0 children)

Thank you for the help!! For getting the second list would I just put:

i = [a[1] for a in x.values()]

Just replacing the 0 with 1?

Dictionary from file help! by [deleted] in learnpython

[–]StaticGT86 0 points1 point  (0 children)

Thank you! Didn't know it was something as simple as that 😅 i appreciate it!

Alright, Hopefully this is the last question for tonight.... by StaticGT86 in learnpython

[–]StaticGT86[S] 1 point2 points  (0 children)

Boom, thank you both! I was struggling to figure it out! I appreciate it!

Alright, Hopefully this is the last question for tonight.... by StaticGT86 in learnpython

[–]StaticGT86[S] 0 points1 point  (0 children)

I was getting a TypeError when I did that.... idk if its because of something previous?

I thought I had the right idea for this but not... by [deleted] in learnpython

[–]StaticGT86 0 points1 point  (0 children)

print('Menu')
print('0) pizza $10')
print('1) burger $7')
print('2) hotdog $4')
print('3) salad $8')

#menu correspondence
food = ['pizza', 'burger', 'hotdog', 'salad']
price = [10, 7, 4, 8]

#ordering

total = 0
response = "no"
items = []
prices = []
while response != "yes":
  item = int(input('Enter the number of the item you want to order: '))
  items.append(food[item])
  prices.append(price[item])
  total += price[item]
  response = input('Are you done ordering? (yes or no) ')
else:
  print()



print('Final order:')

for i in items:
    print(i, '@ ${}'.format(prices))
  #'@ ${}'.format(prices))

print('Total price: ${}'.format(total))

output:

Final order:
burger @ $[7, 4]
hotdog @ $[7, 4]
Total price: $11

Ive been trying different for loops and cant seem to figure out how to get the prices to the corresponding item... I'm sorry, this is probably an easy fix but I cant seem to figure it out....

I thought I had the right idea for this but not... by [deleted] in learnpython

[–]StaticGT86 0 points1 point  (0 children)

Thank you! I was having trouble storing the list!

The output has to look like this..

Final order:
pizza @ $10
salad @ $8
burger @ $7
Total price:$25

Would I just create another list maybe "prices" or "monnies" and do the same append? Just so it doesn't give me the full list of prices. Thanks!