heapq모듈에 있는 nlargeest(), nsmallest() 함수
heapq 모듈에 있는 nlargest()와 nsmallest() 함수를 사용해서 최대 or 최소값을 찾을 수 있다. 기본적인 함수 형태heapq.nlargest(n, iterable, key=None) heapq.nsmallest(n, iterable, key=None) 사용 >>> import heapq>>> nums = [1, 3, 6, 34, 5, 22, 67, -3, 56, -9]>>> print(heapq.nlargest(5, nums))[67, 56, 34, 22, 6]>>> print(heapq.nsmallest(3, nums))[-9, -3, 1] key 파라미터를 사용해 보겠다. >>> data = [ {'title': 'Sams', 'famous': 100, 'price':230.0}..
2014. 12. 19.