1

When I use int

a = [1, 2, 3]
b = [3, 1, 2]

print(all(a) in b)

the result is True.

But, when I use characters

a = ["a", "b", "c"]
b = ["c", "b", "a"]

print(all(a) in b)

the result is False

Why in this case result is False?

Ann Zen
  • 25,080
  • 7
  • 31
  • 51
Alex
  • 29
  • 2

1 Answers1

2

all(a) in both cases returns True, so you are basically running

print(True in [3, 1, 2])

and

print(True in ["c", "b", "a"])

True == 1 returns True in python, so since there is the value 1 inside the integer b list, True in b returns True for the integer b list.

And because True woundn't equal to any string, True in b returns False for the string b list

Ann Zen
  • 25,080
  • 7
  • 31
  • 51