Sep-20-2016, 02:58 PM
(Sep-20-2016, 04:43 AM)Gengar Wrote:>>> def orderize(array): ... is_complete = False ... i, x = 0 ... ordered_list = [] ... while not is_complete: ... if array[i] == x: ... ordered_list.append(array[i]) ... if ordered_list.__len__() == 5: ... is_complete = True; continue ... if i == 4: ... i, x = 0 ... continue ... i+=1 ... x+=1
Lets start at the top of your while loop and work our way down...
1) why are you comparing the content of the array at a certain index... with that index? (x and i always have the same value, since you always increment them together and set them to 0 together).
2) why are you using __len__() instead of len()?
3) why are you comparing the length of the ordered list to 5? You'll only ever be sorting arrays that are exactly 5 items long? Why not... "if len(ordered_list) == len(array):"?
4) "if i==4:"... what? Why? Why would you care if the index is 4?