Question #410   Submitted by Answiki on 03/08/2021 at 03:20:34 PM UTC

How to switch array list in Python?

Answer   Submitted by Answiki on 03/08/2021 at 04:00:16 PM UTC

The simplest way to switch two lists in Python is to use a third temporary list (C in the following example):

# Create lists A and B
A = [1,2,3,4]
B = ['a', 'b', 'c']

# Switch lists A and B (A <=> B)
C = A
A = B
B = C

The following displays the whitched lists:

>>> print (A, B)
['a', 'b', 'c'] [1, 2, 3, 4]


3 events in history
Answer by Answiki on 03/08/2021 at 04:00:16 PM

The simplest way to switch two lists in Python is to use a third temporary list (C in the following example):

# Create lists A and B
A = [1,2,3,4]
B = ['a', 'b', 'c']

# Switch lists A and B (A <=> B)
C = A
A = B
B = C

The following displays the whitched lists:

>>> print (A, B)
['a', 'b', 'c'] [1, 2, 3, 4]


Answer by Answiki on 03/08/2021 at 03:27:56 PM

The simplest way to switch two lists in Python is to use a third temporary list (C in the following example):

# Create lists A and B
A = [1,2,3,4]
B = ['a', 'b', 'c']

# Switch lists A and B (A <=> B)
C = A
A = B
B = C

The following displays the whitched lists:

>>> print (A, B)
['a', 'b', 'c'] [1, 2, 3, 4]


Question by Answiki 03/08/2021 at 03:20:34 PM
How to switch array list in Python?
# ID Query URL Count

Icons proudly provided by Friconix.