|
12 | 12 | "#### `range`\n", |
13 | 13 | "generate a sequence of integers in the specified \"range\":\n", |
14 | 14 | "```python\n", |
15 | | - ">>> range(10)\n", |
16 | 15 | "# will generate 0.. 1.. 2.. ... 8.. 9\n", |
| 16 | + "range(10)\n", |
17 | 17 | "```\n", |
18 | 18 | "\n", |
19 | 19 | "#### `enumerate`\n", |
20 | 20 | "\"enumerate\" the items in an iterable:\n", |
21 | 21 | "```python\n", |
22 | | - ">>> enumerate([\"apple\", \"banana\", \"cat\", \"dog\"])\n", |
23 | 22 | "# will generate (0, 'apple').. (1, 'banana').. (2, 'cat').. (3, 'dog')]\n", |
| 23 | + "enumerate([\"apple\", \"banana\", \"cat\", \"dog\"])\n", |
24 | 24 | "```\n", |
25 | 25 | "\n", |
26 | 26 | "#### `zip`\n", |
|
30 | 30 | ">>> exam_1_scores = [90, 82, 79, 87]\n", |
31 | 31 | ">>> exam_2_scores = [95, 84, 72, 91]\n", |
32 | 32 | "\n", |
33 | | - ">>> zip(names, exam_1_scores, exam_2_scores)\n", |
34 | 33 | "# will generate ('Angie', 90, 95).. ('Brian', 82, 84).. ('Cassie', 79, 72).. ('David', 87, 91)]\n", |
| 34 | + ">>> zip(names, exam_1_scores, exam_2_scores)\n", |
| 35 | + "<zip at 0x20de1082608>\n", |
35 | 36 | "```\n", |
36 | 37 | "***\n", |
37 | 38 | "The following are some of the many useful tools provided by the `itertools` module:\n", |
|
45 | 46 | ">>> iter_3 = [\"moo\", \"cow\"]\n", |
46 | 47 | ">>> iter_4 = \"him\"\n", |
47 | 48 | "\n", |
48 | | - ">>> chain(gen_1, gen_2, iter_3, iter_4)\n", |
49 | 49 | "# will generate: 0.. 2.. 4.. 9.. 16.. 25.. 'moo'.. 'cow'.. 'h'.. 'i'.. 'm'\n", |
| 50 | + ">>> chain(gen_1, gen_2, iter_3, iter_4)\n", |
| 51 | + "<itertools.chain at 0x20de109ec18>\n", |
50 | 52 | "```\n", |
51 | 53 | "\n", |
52 | 54 | "#### `itertools.combinations`\n", |
53 | 55 | "Generate all length-n \"combinations\" from an iterable:\n", |
54 | 56 | "```python\n", |
55 | 57 | ">>> from itertools import combinations\n", |
56 | | - ">>> combinations([0, 1, 2, 3], 3) # generate all length-3 combinations from [0, 1, 2, 3]\n", |
| 58 | + "\n", |
57 | 59 | "# will generate: (0, 1, 2).. (0, 1, 3).. (0, 2, 3).. (1, 2, 3)\n", |
| 60 | + ">>> combinations([0, 1, 2, 3], 3) # generate all length-3 combinations from [0, 1, 2, 3]\n", |
| 61 | + "<itertools.combinations at 0x20de10a7728>\n", |
58 | 62 | "```" |
59 | 63 | ] |
60 | 64 | } |
|
76 | 80 | "name": "python", |
77 | 81 | "nbconvert_exporter": "python", |
78 | 82 | "pygments_lexer": "ipython3", |
79 | | - "version": "3.6.4" |
| 83 | + "version": "3.6.3" |
80 | 84 | } |
81 | 85 | }, |
82 | 86 | "nbformat": 4, |
|
0 commit comments