For any and all questions relating to Challenge 4 post away!
This challenge was fun to do.
A few tips:
You can loop through a dictionary using a_dict.items(), for examples
for key, value in a_dict.items(): #do something with the key #do something with the value
You can also loop through an iterable you make up on the spot. For example
list1=[1,2,3,4] list2=[5,6,7,8] list3=[9,10,11,12] for i in [list1,list2,list3] for j in i: #do something with j #do something with i
The main problem with this is that you can never access this list ever again. To get around this, you could make a temporary list.
temp_list = [list1,list2,list3] for i in temp_list: #do whatever
Finally, the question asks you to sum things up. I wonder if python has a function that would help you would with that. Hmmmmmm…
I will be moderating this forum for the next 2 hours. Feel free to ask any clarifying questions and discuss amongst yourselves without sharing answers.
That was a fun one.
Tip: There’s a handy function called max() that gets the max value in a dictionary.
max_amt_in_dict = max(dictionary,key=dictionary.get)
I got the correct answer, but am not too sure how the challenge wants us to do this…seems like a lot of unnecessary work
Hi all, I will be moderating the forum for the next 2 hours. Please let me know if you face any barriers in attempting to complete todays challenge. Also, please remember to not share any answers on this forum.
My god this took me waay longer than it should have haha. Atleast I completed it
How would you use this in real life? Can you provide any examples here?
Just being cheeky.
I’ve always been told tipping is considered rude in most European cultures. So wouldn’t the tip be 0 regardless
I used list function to list values of of the various meals/starters/desserts/beers and then chose the max value function to find the maximum value in the list. problem is not I cannot add the highest values of various items because they are type list and not float. what can I do?
you could attempt to cast each element as a type float. Or write a custom function that gets the maximum using a for loop.