n=int(input('total number of items in list')) L=[] for i in range(n): item=int(input('enter the item')) L.append(item) n=int(input('total number of items in list')) L=[] for i in range(n): item=int(input('enter the item')) L.append(item) for i in range(1,n): k=L[i] j=i-1 while j>=0 and k<L[j]: L[j+1]=L[j] j=j-1 else: L[j+1]=k print('sorted list:\n',L)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter