Welcome to the CSC Q&A.
Get help and give help!
Write great code!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+5 votes

I'm having trouble getting my new list to switch off between one index from each list. I can either only have the values from one of the lists or when I do a nested loop I get something like one value from list 1, then all of list 2, then the next value from list 1, all of list 2, and so on. Any tips?

asked in CSC201 Spring 2021 by (8 points)

3 Answers

+2 votes

the length for both the lists is the same, so we do the for loop to find the num index for each list, then we append it into the empty list:
if you need to append each element at a time, you need to append at a time under for loop such that you do

newList.append(list1[num]) then newList.append(list2[num])

rather than adding them up.

answered by (8 points)
+1 vote

Could you explain any more how you are currently doing it?

answered by (8 points)
+1

Oops, I figured out what I was doing! Thanks for the help though!!

+1 vote

Since the prompt states that we can assume two lists have the exact same length, you just need to do the for loop once. Then add each element from list 1 and list 2 to a new empty list.

answered by (8 points)
...