0

I was watching a video where all of a sudden the instructor uses the given code to swap two elements of a list L:

L[suffix], L[i] = L[i], L[suffix]

What is the procedure undertaken inside for this method of swap? Is a new list formed? Or a tuple? Or a dictionary? Or something else???

stelioslogothetis
  • 9,371
  • 3
  • 28
  • 53
Aaron John Sabu
  • 297
  • 1
  • 2
  • 13

1 Answers1

1

It's easy to understand

>>> L = [0,4]
>>> L[0],L[1] = L[1],L[0]
>>> L
[4, 0]

Or this example,in this case you swap first and third element

>>> P = [0,4,9]
>>> P[0],P[2] = P[2],P[0]
>>> P
[9, 4, 0]
Richard Rublev
  • 7,718
  • 16
  • 77
  • 121