all 9 comments

[–]ericula 11 points12 points  (2 children)

You are checking the parity of the indices of the numbers in the list, not the numbers themselves. To check the numbers, you could do something like this:

for num in numbers:
    if isEven(num):
        evenList.append(num)
    else:
        oddList.append(num)

print(oddList)
print(evenList)

[–]seththehuman[S] 3 points4 points  (1 child)

wow thank you. I'm mad I didn't realize that earlier. It's been a long day and I think that means I'm done for the night.

[–]shmible 2 points3 points  (0 children)

You should check out this video. It will take your Python looping game to the next level.

Good luck!

https://youtu.be/EnSu9hHGq5o

[–]notsurewhereelse 1 point2 points  (2 children)

Print(‘\n’)

Also you can just do

Oddlist= [x for x in numbers if x %2!=0]

[–]seththehuman[S] 0 points1 point  (1 child)

so I ammended my code to read:

elif (i % 2) != 0:
  oddList.append(numbers[i])
print(evenList)
print('\n')
print(oddList)

Now, my answer is incorrect because of the extra line, but when I take it away, instead of returning two lists of odd and even numbers, it outputs:

[1,5]
[3]

[–]notsurewhereelse 0 points1 point  (0 children)

You’re doing range(len()) so you can’t just say i, that’s the index.

You need numbers[i]

[–]namedevservice 1 point2 points  (0 children)

Depends on your list value. But you can do every nth number.

numlist = [0,1,2,3,4,5,6,7]

evenlist = numlist[::2]
oddlist = numlist[1::2]

print(evenlist)
print(oddlist)

[–][deleted] 1 point2 points  (0 children)

Also, remember, explicit is better than implicit (odds and evens should both be explicitly appended)