I have looked at SO How can I reorder a list in python? for a solution. Yet, when I run my code, in 1 Python shell it works, and in the other it does not. Both are version 2.7. (EDIT: one version is 2.7, the other 3.2) The part of the code for v 2.7 where I receive an error (for v 3.2) is the following:
for r in range(c): # c = 3 as I make 3 changes in the list
p[list_a[r]], p[list_b[r]] = p[list_b[r]], p[list_a[r]] # IndexError: list index out of range
# p = [1, 2, 3, 4, 5] # p = starting list
# list_a = [1,1,4]
# list_b = [2,3,0]
# ** Alternatively (brings same result): **
#temp = p[list_a[r]] # IndexError: list index out of range
#p[list_a[r]] = p[list_b[r]]
#p[list_b[r]] = temp
Why would I get different results (working or not working) for same version of Python? And how can I solve the IndexError? Thank you for your help.
EDIT: It seems that the online shell is in Python version 3.2. So may this be the reason why that version is giving me an error message?