Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import heapq
- import random
- data = [random.randint(0, 9) for x in range(10)]
- print("A:", data)
- heapq.heapify(data)
- print("B:", data)
- data = heapq.nsmallest(10, data)
- print("C:", data)
- print()
- data = list(reversed(range(10)))
- print("A:", data)
- heapq.heapify(data)
- print("B:", data)
- data = heapq.nsmallest(10, data)
- print("C:", data)
- '''
- A: [5, 6, 5, 3, 4, 5, 4, 0, 8, 0]
- B: [0, 0, 4, 3, 4, 5, 5, 5, 8, 6]
- C: [0, 0, 3, 4, 4, 5, 5, 5, 6, 8]
- A: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
- B: [0, 1, 3, 2, 5, 4, 7, 9, 6, 8]
- C: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
- '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement