Python: Sorting One million values using Seclection Sort

My program hangs in sorting loop. I thought its a integer size limit but other post says that Python is good at large numbers. It works fine for random values but random values generation (in my program) actually don’t use large numbers (i.e. seed). Even the sorting is not using large numbers, so it might be program logic but also a memory problem which python is not complaining.
Any way somebody please provide me a practical solution.
Program works fine with small values.

import random
import psutil
import os

class SSSort:
    arr = []  # class var access by className.arr

    def __init__(self, n):
        self.n = n

    def generate1000000_5digit_RandomNum(self):
        for i in range(self.n):
            num = random.randint(10000, 99999)

        for j in range(self.n):
            print("random {0}".format(SSSort.arr[j]))

    def find_the_min_element(self, i):
        min = i
        for j in range(i+1, self.n):
           if (SSSort.arr[j] < SSSort.arr[min]):
              min = j
        return min
              #print("min {}".format(min))

    def selectionSort(self):
        for i in range(self.n):
            min = self.find_the_min_element(i)
            #swap min and ith element of array
            temp = SSSort.arr[min]
            SSSort.arr[min] = SSSort.arr[i]
            SSSort.arr[i] = temp

        for i in enumerate(SSSort.arr):


    def main(self):

if __name__ == "__main__":
    objSSSort = SSSort(1000000)

Output: shows the random values but hangs up in the sorting loop

Somebody please solve my problem.


I’m just starting to look at the code, but I have two questions.

  1. Does it work when you use 500 numbers? 50?
  2. Are you required to use selection sort? It’s not going to be super quick.

A post was merged into an existing topic: Python: Program hangs up with large integer count

I went ahead and combined your posts for you. Please use the edit button instead of multi-posting next time. Thank you.