vegaseat
DaniWeb's Hypocrite
6,499 posts since Oct 2004
Reputation Points: 1,451
Solved Threads: 1,618
Skill Endorsements: 39
"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', 'a', 'c', 'b'], ['a', 'b', 'b', 'd', 'e', 'e', 'f', 'g']):
print t, in_order(t)
woooee
Posting Maven
2,717 posts since Dec 2006
Reputation Points: 827
Solved Threads: 781
Skill Endorsements: 9
The built-in Python functions sorted() and sort() are highly optimized and a good choice to use.
Ene Uran
Posting Virtuoso
1,830 posts since Aug 2005
Reputation Points: 676
Solved Threads: 255
Skill Endorsements: 7
Question Answered as of 3 Months Ago by
vegaseat,
Ene Uran
and
woooee