Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

selection sort python

#Selection Sorting


def selection_sort(numbers):

  print("Before Sorting:", numbers)  #size/length is = 5

  for i in range(len(numbers)-1): #0,1,2,3 (Iteration 4)

      #finding the minimum value from partition to rest of data
      #partition/index is moving to right
    
      for j in range(i+1, len(numbers)):
       
        #comparing the selected index value with its next index value

        if numbers[j] < numbers[i]:
          
          #swapping partition's left value with the right value

          numbers[i], numbers[j] =  numbers[j], numbers[i]

  print('After Sorting:', numbers)

selection_sort([17, 3, 9, 2, 21, 3, 2])
Comment

PREVIOUS NEXT
Code Example
Python :: divide a column value in pandas dataframe 
Python :: open and read a file in python 
Python :: delete directory if exists python 
Python :: integer colomn to datetime pandas 
Python :: pandas select columns by index 
Python :: how to reset index after dropping rows pandas 
Python :: convert string to integer in dictionary python 
Python :: multiple values in python loop for x,y 
Python :: how to create a list in python 
Python :: pandas read from txt separtion 
Python :: python merge two dictionaries in a single expression 
Python :: sort a series pandas 
Python :: python groupby sum single columns 
Python :: python get file path from in os.walk 
Python :: python tkinter scrollbar widget 
Python :: randomforestregressor in sklearn 
Python :: python send http request 
Python :: how to get a number from a string in python 
Python :: pandas sort by columns 
Python :: merge three dataframes pandas based on column 
Python :: how to import file from another directory in python 
Python :: sqlite query in python 
Python :: how to save a python object in a file 
Python :: standard scaler vs min max scaler 
Python :: how to open application using python 
Python :: python count empty lines in text file 
Python :: pandas column name equal to another column value 
Python :: python copy deep arrays without reference 
Python :: numpy add new column 
Python :: python library to make qr codes 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =