Basta Fazoolin' - Can bill calculation be consolidated?

Challenge link:

In the challenge " Basta Fazoolin’" we create a method to calculate the total bill based on the menus we defined earlier in the challenge.

My question is: Is there a way to access the items in all menus such that we can check items in all of them at once - removing the need to define calculation for each menu?

Can this be done without consolidating the menus in some way?


<thing_that_accesses_all_menus>.calculate(['brunch item', 'early bird item', 'kids item'])

Just asking out of curiosity in order to understand if this class can be streamlined. Thanks!

That sounds a lot like a function to me. Without consolidating menus? Perhaps. If each valid menu was checked in turn somehow.

1 Like

I think you’re right. I keep looking at this and I don’t see anything that would reference all the menus at once. I was hoping for some “magical” class-related thing that could see it all. :wink:

1 Like

typically if you have several of something, you’d stick it into a list

1 Like

There’s no built-in that I’m aware of. If you searched around you might find a way you’d prefer to do it. First thing that popped up (there are plenty of similar queries)-

things that can be described as magical are generally surprising and difficult to reason about, and you won’t find too much such things in python unless you look at certain libraries. instead you’d be looking at how YOU can implement it, which you largely figure out from describing how you want it to behave - if you’re too vague then you won’t have enough details to meaningfully implement it

applying a function to several things is a common operation, see map

bundling them together would be a separate problem, and your constraints around that probably also says how one would do it. if you mean that all instances should be tracked, then you are talking about __init__, however a global list is probably not a universally good idea here, because then two pieces of unrelated code would interfere with one another, what makes more sense is to use the grouping you already have, a Franchise

1 Like