Python Forum
Why do I get this traceback?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Why do I get this traceback?
#5
(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?
Reply


Messages In This Thread
Why do I get this traceback? - by Gengar - Sep-20-2016, 04:43 AM
RE: Why do I get this traceback? - by micseydel - Sep-20-2016, 04:55 AM
RE: Why do I get this traceback? - by Gengar - Sep-20-2016, 05:02 AM
RE: Why do I get this traceback? - by micseydel - Sep-20-2016, 05:09 AM
RE: Why do I get this traceback? - by nilamo - Sep-20-2016, 02:58 PM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020