Welcome, guest | Sign In | My Account | Store | Cart

BitSort in python. using bitarray library

Python, 14 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#-*-coding:utf-8-*-

from bitarray import bitarray

def bitsort(list_to_sort):
    a = bitarray(max(list_to_sort)+1)
    a.setall(False)
    for n in list_to_sort:
        a[n] = True
    return [i for i,val in enumerate(a) if val]


if __name__ == "__main__":
    print bitsort([17, 8, 27, 16, 26, 1, 5, 0, 24])
Created by wong2 on Sun, 19 Jun 2011 (MIT)
Python recipes (4591)
wong2's recipes (2)

Required Modules

Other Information and Tasks