def is_sorted(t):
if t == sorted(t):
return True
else:
return False
print is_sorted([1,2,2]) # True
print is_sorted(['b','a']) # False
print is_sorted([3, 1, 5, 2, 4]) # False
print is_sorted(['d', 'a', 'c', 'b']) # False
print is_sorted(['a', 'b', 'b', 'd', 'e', 'e', 'f', 'g']) # True
jeremywduncan
-1
Newbie Poster
Recommended Answers
Jump to Post... and your problem is?
Jump to Post"Better" is in the eye of the beholder. The first rule is that the program does what it is supposed to.
def in_order(t): for ctr in range(1, len(t)): if t[ctr-1] > t[ctr]: return False return True for t in ([1,2,2], ['b','a'], [3, 1, 5, 2, 4], ['d', …
All 5 Replies
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
jeremywduncan
-1
Newbie Poster
woooee
814
Nearly a Posting Maven
Ene Uran
638
Posting Virtuoso
jeremywduncan
-1
Newbie Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.