# write a function that accepts a list and the indexes of two elements in the list,
# and swaps that two elements of the list, and return the swapped list.
# for example, if the arguments of the function are [23,65,19,90]m index1 = 1, and index2 = 3,
# then it will return [23,90,19,65].
# Swap function
def swapLst(newLst):
size = len(newLst)
# Swapping
temp = newLst[0]
newLst[0] = newLst[size - 1]
newLst[size - 1] = temp
return newLst
newLst = [23,65,19,90]
print(swapLst(newLst))
Здравствуйте, мой вопрос: как я могу изменить свой код, чтобы изменить любой индекс в списке. Моя программа меняет только первый и последний индекс, мне нужна была помощь в этом. Спасибо!
[code]# write a function that accepts a list and the indexes of two elements in the list, # and swaps that two elements of the list, and return the swapped list. # for example, if the arguments of the function are [23,65,19,90]m index1 = 1, and index2 = 3, # then it will return [23,90,19,65].
newLst = [23,65,19,90] print(swapLst(newLst)) [/code] Здравствуйте, мой вопрос: как я могу изменить свой код, чтобы изменить любой индекс в списке. Моя программа меняет только первый и последний индекс, мне нужна была помощь в этом. Спасибо!