Skip to content

Commit 55adb46

Browse files
committed
add slice and map
1 parent 1aac93f commit 55adb46

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

py3/advance/do_slice.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
L = ['Michael', 'Sarah', 'Tracy', 'Bob', 'Jack']
5+
6+
print('L[0:3] =', L[0:3])
7+
print('L[:3] =', L[:3])
8+
print('L[1:3] =', L[1:3])
9+
print('L[-2:] =', L[-2:])
10+
11+
R = list(range(100))
12+
print('R[:10] =', R[:10])
13+
print('R[-10:] =', R[-10:])
14+
print('R[10:20] =', R[10:20])
15+
print('R[:10:2] =', R[:10:2])
16+
print('R[::5] =', R[::5])

py3/functional/do_map.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/usr/bin/env python3
2+
# -*- coding: utf-8 -*-
3+
4+
def f(x):
5+
return x * x
6+
7+
print(list(map(f, [1, 2, 3, 4, 5, 6, 7, 8, 9])))

0 commit comments

Comments
 (0)