Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Second solution in Clear category for Bigger Price by colinmcnicholl
from operator import itemgetter
def bigger_price(limit, data):
"""Input: int (the 'TOP' limit amount of goods) and list of dicts,
(the data). Each dicts has two keys "name" and "price".
Given a table with all available goods in the store.
The Function finds the TOP most expensive goods.
Output: The same as the second Input argument, a list of dicts.
"""
return sorted(data, key=itemgetter('price'), reverse=True)[:limit]
if __name__ == '__main__':
#These "asserts" using only for self-checking and not necessary 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')
Feb. 21, 2019
Comments: