Sorted list in Python

The easiest way was to use ** PriorityQueue ** or ** bisect **, which supports binary search. I'd like to find out how to set the comparison function by myself (whether it can be done) and how the performance is.

bisect

from bisect import insort
q = []
insort(q, 1)
insort(q, 10)
insort(q, 2)
insort(q, 5)
insort(q, 3)
print(q) # [1, 2, 3, 5, 10]

PriorityQueue

import Queue as Q
q = Q.PriorityQueue()
q.put(1)
q.put(10)
q.put(2)
q.put(5)
q.put(3)

# 1, 2, 3, 5,Output in order of 10
while q.qsize() > 0:
  print(q.get())

Recommended Posts

Sorted list in Python
Filter List in Python
List find in Python
[Python] list
Getting list elements in Python
Extract multiple list duplicates in Python
Difference between list () and [] in Python
[python] Manage functions in a list
Output 2017 Premium Friday list in Python
Delete multiple elements in python list
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python
Python 3.3 in Anaconda
Python basics: list
Geocoding in python
SendKeys in Python
Meta-analysis in Python
Unittest in python
Epoch in Python
Discord in Python
Sudoku in Python
DCI in Python
quicksort in python
nCr in python
N-Gram in Python
Programming in python
Plink in Python
Constant in python
Lifegame in Python.
FizzBuzz in Python
Sqlite in python
Python> Comprehension / Comprehension> List comprehension
StepAIC in Python
N-gram in python
LINE-Bot [0] in Python
Csv in python
Disassemble in Python
Reflection in Python
Constant in python
nCr in Python.
format in python
Scons in Python3
Puyo Puyo in python
python in virtualenv
PPAP in Python
Quad-tree in Python
Reflection in Python
Chemistry in Python
Hashable in python
Python list manipulation
DirectLiNGAM in Python
LiNGAM in Python
Flatten in python
flatten in python
Display a list of alphabets in Python 3
OR the List in Python (zip function)
Difference between append and + = in Python list
Download images from URL list in Python
Summary of built-in methods in Python list