def bitsort(filename, maxn):
    """ Sort a file named 'filename' which
    consists of maxn integers where each
    integer is less than maxn """

    # Initialize bitmap
    a = [0]*maxn

    # Read from file and fill bitmap
    for line in file(filename):
        n = int(line.strip())
        # Turn bits on for numbers
        if n<maxn: a[n] = 1

    # Return a generator that iterates over the list
    for n in range(len(a)):
        if a[n]==1: yield n
 Sort a file named 'filename' which
    consists of maxn integers where each
    integer is less than maxn 
recipes/Python/528942_Bitsort_algorithm/recipe-528942.py