Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
HOME - "Bigger Price" solution in Uncategorized category for Bigger Price by jsg-inet
def bigger_price(limit: int, data: list) -> list:
"""
TOP most expensive goods
"""
# your code here
def max_price_element(set:list)-> dict:
max_element=[]
max_price=0
for x in set:
if x["price"]>max_price:
max_price=x.get("price")
max_element=x
return max_element
top_prices=[]
for i in range(limit):
new_element=max_price_element(data)
top_prices.append(new_element)
data.remove(new_element)
return top_prices
if __name__ == '__main__':
from pprint import pprint
print('Example:')
pprint(bigger_price(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]))
# These "asserts" using for self-checking and not for auto-testing
assert bigger_price(2, [
{"name": "bread", "price": 100},
{"name": "wine", "price": 138},
{"name": "meat", "price": 15},
{"name": "water", "price": 1}
]) == [
{"name": "wine", "price": 138},
{"name": "bread", "price": 100}
], "First"
assert bigger_price(1, [
{"name": "pen", "price": 5},
{"name": "whiteboard", "price": 170}
]) == [{"name": "whiteboard", "price": 170}], "Second"
print('Done! Looks like it is fine. Go and check it')
June 11, 2021