def is_ascending(items):
if len(items) == 0 or 1:
return True
for i in range(len(items) - 1):
if items[i] >= items[i + 1]:
return False
return True
Asked
Active
Viewed 26 times
-1

j1-lee
- 13,764
- 3
- 14
- 26

Jacopo Stifani
- 141
- 1
- 6
-
Problem is with 0 or 1. You need to check the condition. ``` if len(items) == 0 or len(items) == 1: ``` – MritiYogan Feb 27 '22 at 05:54
1 Answers
1
if len(items) == 0 or 1:
This snippet doesn't do what you think it does. It's essentially evaluated like
if (len(items) == 0) or (1):
which is always True since the part after the "or" is True (so the whole function returns True. What you want is
if (len(items) == 0) or (len(items) == 1):
or simpler
if len(items) <= 1:

xjcl
- 12,848
- 6
- 67
- 89