File tree Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Expand file tree Collapse file tree 3 files changed +46
-1
lines changed Original file line number Diff line number Diff line change 1
1
# functions and modules
2
2
3
3
## MinMax
4
+
4
5
- difficulty: ★☆☆
5
6
- time: ~ 15m for beginners
6
7
- background: list, iteration
7
8
8
9
Implement ` min ` , ` max ` functions on your own.
9
10
11
+ ## Swap Index
12
+
13
+ - difficulty: ★☆☆
14
+ - time: ~ 15m for beginners
15
+ - background: list
16
+
17
+ Implement a function which swaps indices of list.
10
18
11
19
## Hanoi
12
20
- difficulty: ★☆☆
@@ -22,4 +30,3 @@ Implement `hanoi` function on your own. `hanoi` function is a guide that tells h
22
30
- background: function, recursion
23
31
24
32
Implement a function which calculates binomial coefficient, $\prescript{}{n}C_k$.
25
-
Original file line number Diff line number Diff line change
1
+ def swap_indices (ls , i , j ):
2
+ """
3
+ Swap ls[i] and ls[j].
4
+
5
+ >>> ls = [0, 1, 2, 3]
6
+ >>> swap_indices(ls, 0, 2)
7
+ >>> ls
8
+ [2, 1, 0, 3]
9
+ >>> swap_indices(ls, 1, 2)
10
+ >>> ls
11
+ [2, 0, 1, 3]
12
+ """
13
+ ls [i ], ls [j ] = ls [j ], ls [i ]
14
+
15
+
16
+ if __name__ == "__main__" :
17
+ import doctest
18
+
19
+ doctest .testmod (verbose = True )
Original file line number Diff line number Diff line change
1
+ def swap_indices (ls , i , j ):
2
+ """
3
+ Swap ls[i] and ls[j].
4
+
5
+ >>> ls = [0, 1, 2, 3]
6
+ >>> swap_indices(ls, 0, 2)
7
+ >>> ls
8
+ [2, 1, 0, 3]
9
+ >>> swap_indices(ls, 1, 2)
10
+ >>> ls
11
+ [2, 0, 1, 3]
12
+ """
13
+ pass
14
+
15
+
16
+ if __name__ == "__main__" :
17
+ import doctest
18
+
19
+ doctest .testmod (verbose = True )
You can’t perform that action at this time.
0 commit comments