Created
October 14, 2016 00:05
-
-
Save itsmuriuki/75913698ba6489dacc8921a1a09f45d6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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