Created
December 23, 2019 17:54
-
-
Save luisenriquecorona/c86a82e53dfdd6279759f27509880791 to your computer and use it in GitHub Desktop.
Sorting is expensive, so once you have a sorted sequence, it’s good to keep it that way. That is why bisect.insort was created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import bisect | |
import random | |
SIZE = 7 | |
random.seed(1729) | |
my_list = [] | |
for i in range(SIZE): | |
new_item = random.randrange(SIZE*2) | |
bisect.insort(my_list, new_item) | |
print('%2d ->' % new_item, my_list) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment