I need to change the number with the highest index and the number with the lowest index between each other in the entered line, but an error pops out
Error:
list2[0], list2[len1] = list2[len1], list2[0]
IndexError: list index out of range
Code:
list1 = input("Введите список: ")
list2 = list1.split()
len1 = int(len(list2))
list2[0], list2[len1] = list2[len1], list2[0]
print(list2)
How can this be fixed?
0the last item of a list isl[len(l) -1]or justl[-1]