I'm new to programming and I'm learning Python. I have to make a function that will swap 2 indices within a list. The list is given but the indices to be swapped need to be input by the user. So far I've been able to come up with this...
def listSwap():
print("This program will swap two indices within a list")
myList = [3, 4, 2, 5, 1, 14, 23, 1]
print("Here is your list... ", myList)
index1 = eval(input("Pick an index from the list you would like to swap... "))
index2 = eval(input("Now pick another index to swap with the first... "))
tempIndex = index1
myList[index1] = myList[index2]
myList[index2] = myList[tempIndex]
print("Here is your new list with swapped indices", myList)
def main():
listSwap()
main()
but it doesn't work like I need it to. It will swap 1 index but not the other. Could I get some help? Maybe explain what I'm doing wrong?