-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathex_10_06.py
29 lines (24 loc) · 845 Bytes
/
ex_10_06.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/python
#AUTHOR: alexxa
#DATE: 28.12.2013
#SOURCE: Think Python: How to Think Like a Computer Scientist by Allen B. Downey
# http://www.greenteapress.com/thinkpython/html/index.html
#PURPOSE: Chapter 10. Lists
# Exercise 10.6
# Write a function called is_sorted that takes a list as
# a parameter and returns True if the list is sorted in
# ascending order and False otherwise. You can assume (as
# a precondition) that the elements of the list can be
# compared with the relational operators <, >, etc.
# For example, is_sorted([1,2,2]) should return True and
# is_sorted(['b','a']) should return False.
def is_sorted(listik):
if sorted(listik) == listik:
return True
else:
return False
print(is_sorted([1,2,2]))
print(is_sorted([1,2,1,2]))
print(is_sorted([]))
print(is_sorted(['b','a']))
#END