Skip to content

Instantly share code, notes, and snippets.

@itsmuriuki
Created October 14, 2016 00:05
Show Gist options
  • Save itsmuriuki/75913698ba6489dacc8921a1a09f45d6 to your computer and use it in GitHub Desktop.
Save itsmuriuki/75913698ba6489dacc8921a1a09f45d6 to your computer and use it in GitHub Desktop.
def wierd_sort (arr): #defining the length of the array
wierd =[] #Empty arry to store sorted arr
myarr = arr[:] #makes a copy of the array
myarr = sorted(myarr) #sorts array
i = 0
while i < len(myarr): #goes through the lenngth of the array
if len(myarr) > 1:
wierd.append(myarr[0]) #appends the first digit into the new arr
wierd.append(myarr[-1]) #appends the last digit into the new arr
myarr.remove(myarr[0]) #removes the first digit from a copy of the initial array
myarr.remove(myarr[-1]) #removes the last digit from a copy of the initial array
i += 1 #incrementing the counter
if len(myarr) ==1:
wierd.append (myarr[0]) #removes the last number of the array
return wierd #brings
print wierd_sort([1,2,3,4,5,6,7,8,9,10])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment