I would suggest to print some data that would help you make sure what the issue is. For example the groups and prices.
Might be a minor error in the formulas or a rounding error in the answer.

I've read the comments and you check for many things in order to decide whether to return -1 or keep going. You could look for a way to make one check to clear them in less operations.

When you pass a function, f, to the key parameter, the elements of the iterable are sorted according to the returned value of that function and not their own value. Basically, the function receives one argument (each element) and maps it to a given value which is used only for establishing the order between elements. This means that for instance e1>e2 if f[e1]>f[e2].

In this case, the returned value of the function (x >= k) is a boolean, and therefore the function maps the elements either to 0 (False), if x<k , or 1 (True) if x>=k. All elements less than k (value 0) will be placed before the elements greater or equal to k (value 1) since 0 < 1.

Note that the original order in the list is still preserved for elements mapped to the same value because they are “equivalent under the function”, and therefore don’t switch position with each other when compared.

\d+ and [0-9]+ are patters, \d+ is just a more clean and good

Of course using max() function, great solution!

I overthought my solution I believe...

Or keep adding them until you pass.

I would suggest to print some data that would help you make sure what the issue is. For example the groups and prices.

Might be a minor error in the formulas or a rounding error in the answer.

I've read the comments and you check for many things in order to decide whether to return -1 or keep going. You could look for a way to make one check to clear them in less operations.

I've actually seen solutions like this before, but I still don't fully understand them...

I think description is lacking a bit, the task itself is interesting.

I only solved it easily because I have done such thing before in real life.

Thank you for bringing this out!

It only generates until it gets a match, or the first value a generator returns.

https://docs.python.org/3/library/string.html#formatspec

it formats the value to display with 5 digits (d = digit)

THAT IS SO COOL! I NEVER KNEW THIS! BUT NOW I DO! MUAHAHAH

A huge thank you to you YesLod!!! Now I get it. Much appreciated!

When you pass a function, f, to the key parameter, the elements of the iterable are sorted according to the returned value of that function and not their own value. Basically, the function receives one argument (each element) and maps it to a given value which is used only for establishing the order between elements. This means that for instance e1>e2 if f[e1]>f[e2].

In this case, the returned value of the function (x >= k) is a boolean, and therefore the function maps the elements either to 0 (False), if x<k , or 1 (True) if x>=k. All elements less than k (value 0) will be placed before the elements greater or equal to k (value 1) since 0 < 1.

Note that the original order in the list is still preserved for elements mapped to the same value because they are “equivalent under the function”, and therefore don’t switch position with each other when compared.

could anybody explain this code please? I don't understand the way lambda sorts the list..

## Loading more items...