A
A
avion2018-04-03 19:01:29
Python
avion, 2018-04-03 19:01:29

Code work in Python?

Hello, help me understand the code.

A = [1, 2, 5, 8, 9, 3, 4, 0, 7, 6]

j = 5

while A[j] < A[j-1]:

    A[j], A[j-1] = A[j-1], A[j]

    j -= 1

print(A)

Specifically, what does this piece of code do?
A[j], A[j-1] = A[j-1], A[j]

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2018-04-03
@avion123678

Swaps values ​​in adjacent positions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question