#First One a = list(map(int, input().split())) n = len(a) small = a[0] #Considering that there is atleast 1 input index = 0 for i in range(1,n): #Starting from 1st, as that will be swapped with the smallest value for j in range(i,n): #No need to check the elements which are already swapped if(small > a[j]): small = a[j] index = j a[i - 1], a[index] = a[index], a[i - 1] small = a[i] index = i print(a) #Second One b = list(map(int, input().split())) n = len(a) small = b[0] #Considering that there is atleast 1 input index = 0 for i in range(1,n): #Starting from 1st, as that will be swapped with the smallest value for j in range(i,n): #No need to check the elements which are already swapped if(small >= b[j]): #To select the last smallest value, rather than the first smallest value small = b[j] index = j if(b[i - 1] != small): #Extra checking to reduce operations to be done if similar values b[i - 1], b[index] = b[index], b[i - 1] small = b[i] index = i print(b) input() #To see the output, not useful
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question