I was wondering if anyone could help me with a Python problem I have. I have four lists, each list holds floats (decimals). I’m adding all the floats that each list contains. The part I’m stuck on is I want to know which of the four list has a higher sum. I know I could use if statements but does anyone know a more of a efficient way. For instance:
foodmart = [12.33,5.55]
nike = [42.20,69.99]
gas_station = [0.89,45.22]
toy_store = [10.99,15.32]
Represent the lists as a
dictand usemaxwith an optionalkeyfunction to calculate thesumInstead of representing the lists in the way you did, use a dictionary. It would be easier to determine the correct shop and work on any number of lists / shops without the need to enumerate them in the max routine. This would be more Pythonic and maintainable