Skip to content

Commit 566b1d7

Browse files
Eric ChouEric Chou
authored andcommitted
added ch12
1 parent 45b1e29 commit 566b1d7

2 files changed

Lines changed: 30 additions & 0 deletions

File tree

‎ch12/ex12_1.py‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env python
2+
3+
def sumall(*args):
4+
s = sum(args)
5+
return s
6+
7+
r = sumall(1,2,3,4,5,6,7,8)
8+
print r
9+

‎ch12/ex12_2.py‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env python
2+
3+
import random
4+
5+
def sort_by_length(words):
6+
t = []
7+
for word in words:
8+
t.append((len(word)+random.random(), word))
9+
10+
t.sort(reverse=True)
11+
12+
res = []
13+
for length, word in t:
14+
res.append(word)
15+
return res
16+
17+
18+
words = ['one', 'eno', 'two', 'owt', 'three', 'eerht']
19+
result = sort_by_length(words)
20+
print result
21+

0 commit comments

Comments
 (0)