Given the lists list1 and list2 that are of the same length, create a new list consisting of the last element of list1 followed by the last element of list2 , followed by the second to last element of list1 , followed by the second to last element of list2 , and so on (in other words the new list should consist of alternating elements of the reverse of list1 and list2 ). For example, if list1 contained [1, 2, 3] and list2 contained [4, 5, 6] , then the new list should contain [3, 6, 2, 5, 1, 4] . Associate the new list with the variable list3 .
My code:
def new(list1,list2):
i = 0
j = 0
new_list = []
for j in list1:
new_list[i-1] = list2[j-1]
i+= 1
j += 1
new_list[i-1] = list2 [j-1]
i+= 1
j += 1
return new_list
I know, it's messy =_=, help?
new_list[i-1] = list2[j-1]
. Alsoj
is a VALUE from list1 but you then use it as a SUBSCRIPT of list2! Suggestion: use test data values of 100, 200, etc -- if you attempt to use those as list subscripts, you'll get an exception immediately, not later. – John Machin