python program to implement pigeonhole sorting in python algorithm for the pigeonhole sorting a 8 3 2 7 4 6 8 b sorteda a nondestructive sort pigeonholesorta a destructive sort a b true size of range of values in the list ie number of pigeonholes we need list of pigeonholes of size equal to the variable size populate the pigeonholes putting the elements back into the array in an order python program to implement pigeonhole sorting in python algorithm for the pigeonhole sorting a 8 3 2 7 4 6 8 b sorted a a nondestructive sort pigeonhole_sort a a destructive sort a b true size of range of values in the list ie number of pigeonholes we need min finds the minimum value max finds the maximum value size is difference of max and min values plus one list of pigeonholes of size equal to the variable size populate the pigeonholes putting the elements back into the array in an order
def pigeonhole_sort(a):
    
    

    min_val = min(a)  
    max_val = max(a)  

    size = max_val - min_val + 1  

    
    holes = [0] * size

    
    for x in a:
        assert isinstance(x, int), "integers only please"
        holes[x - min_val] += 1

    
    i = 0
    for count in range(size):
        while holes[count] > 0:
            holes[count] -= 1
            a[i] = count + min_val
            i += 1


def main():
    a = [8, 3, 2, 7, 4, 6, 8]
    pigeonhole_sort(a)
    print("Sorted order is:", " ".join(a))


if __name__ == "__main__":
    main()