from sortedcontainers import SortedList from math import log values = SortedList([9, 4, 16]) print(log(values.pop(), 2))