|
477 | 477 | "metadata": {}, |
478 | 478 | "source": [ |
479 | 479 | "The following function loops through the words in the list.\n", |
480 | | - "For each one, it reverses the letters and then checks whether the reversed word in the word list." |
| 480 | + "For each one, it reverses the letters and then checks whether the reversed word is in the word list." |
481 | 481 | ] |
482 | 482 | }, |
483 | 483 | { |
|
505 | 505 | "If it doesn't find what it's looking for -- which happens most of the time -- it has to search all the way to the end." |
506 | 506 | ] |
507 | 507 | }, |
| 508 | + { |
| 509 | + "cell_type": "markdown", |
| 510 | + "id": "fac41347", |
| 511 | + "metadata": { |
| 512 | + "tags": [] |
| 513 | + }, |
| 514 | + "source": [ |
| 515 | + "To measure how long a function takes, we can use `%time` which is one of Jupyter's \"built-in magic commands\".\n", |
| 516 | + "These commands are not part of the Python language, so they might not work in other development environments." |
| 517 | + ] |
| 518 | + }, |
508 | 519 | { |
509 | 520 | "cell_type": "code", |
510 | 521 | "execution_count": 58, |
|
590 | 601 | "This function takes less than one hundredth of a second, so it's about 10,000 times faster than the previous version." |
591 | 602 | ] |
592 | 603 | }, |
| 604 | + { |
| 605 | + "cell_type": "markdown", |
| 606 | + "id": "4cd91c99", |
| 607 | + "metadata": {}, |
| 608 | + "source": [ |
| 609 | + "In general, the time it takes to find an element in a list is proportional to the length of the list.\n", |
| 610 | + "The time it takes to find a key in a dictionary is almost constant -- regardless of the number of items." |
| 611 | + ] |
| 612 | + }, |
593 | 613 | { |
594 | 614 | "cell_type": "code", |
595 | 615 | "execution_count": 62, |
|
602 | 622 | "%time much_faster()" |
603 | 623 | ] |
604 | 624 | }, |
605 | | - { |
606 | | - "cell_type": "markdown", |
607 | | - "id": "4cd91c99", |
608 | | - "metadata": {}, |
609 | | - "source": [ |
610 | | - "In general, the time it takes to find an element in a list is proportional to the length of the list.\n", |
611 | | - "The time it takes to find a key in a dictionary is almost constant -- regardless of the number of items." |
612 | | - ] |
613 | | - }, |
614 | 625 | { |
615 | 626 | "cell_type": "markdown", |
616 | 627 | "id": "b3bfa8a5", |
|
1201 | 1212 | "In the notebook for this chapter, you'll see where these measurements come from." |
1202 | 1213 | ] |
1203 | 1214 | }, |
1204 | | - { |
1205 | | - "cell_type": "markdown", |
1206 | | - "id": "c6f39f84", |
1207 | | - "metadata": { |
1208 | | - "tags": [] |
1209 | | - }, |
1210 | | - "source": [ |
1211 | | - "To measure how long a function takes, we can use `%time` which is one of Jupyter's \"built-in magic commands\".\n", |
1212 | | - "These commands are not part of the Python language, so they might not work in other development environments." |
1213 | | - ] |
1214 | | - }, |
1215 | 1215 | { |
1216 | 1216 | "cell_type": "code", |
1217 | 1217 | "execution_count": 50, |
|
0 commit comments