It's been over a year since COVID-19 changed my lifestyle. I'm glad there is a mart is pretty near my house. I can go there quickly, buy food for my family, and come back asap.
Somehow, let's recall the types by making the items bought at the market today into a python dictionary. for just for fun. I used Python Dictionary Merge Operator | ( Python 3.9 features) also ChainMap
the result will be something like this...
<class 'dict'> {'cola': 2.49, 'gingerale': 2.49, 'NN chips': 1.49, 'Roast': 8.99, 'oreo golden': 2.99, 'cheese': 2.49, 'egg': 4.99, 'orange juice': 2.99, 'lactose free 1%': 9.49, 'french van': 7.29}
<class 'dict'> {'oreo golden': 2.99, 'cola': 2.49, 'Roast': 8.99, 'orange juice': 2.99, 'lactose free 1%': 9.49, 'NN chips': 1.49, 'gingerale': 2.49, 'egg': 4.99, 'french van': 7.29, 'cheese': 2.49}
<class 'set'> {('oreo golden', 2.99), ('cola', 2.49), ('Roast', 8.99), ('orange juice', 2.99), ('lactose free 1%', 9.49), ('NN chips', 1.49), ('gingerale', 2.49), ('egg', 4.99), ('french van', 7.29), ('cheese', 2.49)}
<class 'list'> [('cola', 2.49), ('gingerale', 2.49), ('NN chips', 1.49), ('Roast', 8.99), ('oreo golden', 2.99), ('cheese', 2.49), ('egg', 4.99), ('orange juice', 2.99), ('lactose free 1%', 9.49), ('french van', 7.29)]
As you see, All_product2:sets are unordered but All_product4:dictionaries are ordered. If you want to preserve order, you need to use an ordered collection. You can use it differently depending on what kind of data you want to collect. try to use frozen as well. enjoy~ :)
I added some more for the total price.
total = 0.00
print('-----------------------------------------')
for item, price in All_products4.items():
total += price
print('Total Price is ' + "{:.2f}".format(round(total, 2)))
-- removed previously for loops and put this
print('Total Price is ' + "{:.2f}".format(round(sum(All_products4.values()), 2)))
feels better than before.
the result will be something like this...