0

In my last program I misprinted while (A[0] < n) with while(A < [n]). I don't understand how...

But everything worked correctly!

Now I noticed that and here is question. What do symbols of comparing actually compare?

Quite searching does not give anything because it is not intended to compare arrays just with <, I think...

A = []

A.append(3)
A.append(2)
A.append(1)

print A
print (A < [2,2,3])

gives

[3, 2, 1]
False

It seems that it really compares A[0] with n. But may be, I am wrong and here I can find some interesting iteractions?

Sorry, if duplicate, I tried to find smth similar

Chanda Korat
  • 2,453
  • 2
  • 19
  • 23
  • 3
    Those are lists, Python compares them element-wise, as with other sequences like strings. The first non-equal element determines which is "bigger". – jonrsharpe Mar 23 '17 at 11:53
  • @jonrsharpe Oh. wow. It is true. Thanks –  Mar 23 '17 at 11:54

1 Answers1

1

If you compare two lists, they are compared element by element. The first non-equal element determines the result.

[1, 1, 1, 1] > [2]
False

[1, 1, 1, 1] > [0, 2]
True
Richy
  • 380
  • 2
  • 10