728x90
Problem: py.checkio.org/en/mission/bigger-price/
My Solution:
def bigger_price(limit: int, data: list) -> list:
"""
TOP most expensive goods
"""
# your code here
return sorted(data, key = (lambda x: x["price"]), reverse = True)[:limit]
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')
728x90
'프로그래밍 문제 > [Python] CheckIO' 카테고리의 다른 글
[CheckIO] non unique elements (0) | 2020.12.22 |
---|---|
CheckIO - Between Markers (0) | 2020.12.21 |
CheckIO - Count digits (0) | 2020.12.14 |
CheckIO - Days between (0) | 2020.12.12 |
CheckIO - first word (0) | 2020.12.11 |
댓글