WAP THAT ASK USER TO ENTER DIFFERENT NOS IN A LIST AND SWAP(INTERCHANGE) THEM
Answers
Answered by
1
Swap elements by value in a list:
︎︎︎a_list = ["a", "b", "c"]
︎︎︎index1 = a_list. index("a")
︎︎︎index2 = a_list. index("c")
︎︎︎a_list[index1], a_list[index2] = a_list[index2],
︎︎︎a_list[index1]
︎︎︎print(a_list)
Similar questions