We have an assignment in my beginning Python class and I am completely lost on it. I have asked some students and most of them were lost and the teacher gave me a very vague answer that did not help me at all.
"Write a function that is passed in a list and 2 index numbers (your function can assume these index numbers are between 0 and len() - 1, inclusive). Your function should swap the values at those index locations.
stuff = [10, 20, 30, 40]
swap(stuff, 0, 2)
[30, 20, 10, 40]"
I have no idea what i'm doing wrong but I'm getting
def swap(list, indexA, indexB):
for item in list:
if item == list[indexA]:
if item == list[indexB]:
I'm not trying to cheat and get my homework done by someone else, so can someone just explain what I am doing wrong or give me a much needed hint to point me in the right direction?
The problem is:
Other Questions & Answers