|
157 | 157 | "cell_type": "code", |
158 | 158 | "collapsed": false, |
159 | 159 | "input": [ |
160 | | - "60 * 24 * 7 * 7" |
| 160 | + "# insert your code here" |
161 | 161 | ], |
162 | 162 | "language": "python", |
163 | 163 | "metadata": {}, |
|
335 | 335 | "cell_type": "code", |
336 | 336 | "collapsed": false, |
337 | 337 | "input": [ |
338 | | - "name = \"Folgert\"\n", |
| 338 | + "# insert your code here\n", |
339 | 339 | "print name" |
340 | 340 | ], |
341 | 341 | "language": "python", |
|
458 | 458 | "cell_type": "code", |
459 | 459 | "collapsed": false, |
460 | 460 | "input": [ |
461 | | - "but_last_letter = name[-2]\n", |
| 461 | + "but_last_letter = # insert your code here\n", |
462 | 462 | "print but_last_letter" |
463 | 463 | ], |
464 | 464 | "language": "python", |
|
561 | 561 | "cell_type": "code", |
562 | 562 | "collapsed": false, |
563 | 563 | "input": [ |
564 | | - "middle_letters = name[2:-2]\n", |
| 564 | + "middle_letters = # insert your code here\n", |
565 | 565 | "print middle_letters" |
566 | 566 | ], |
567 | 567 | "language": "python", |
|
598 | 598 | "collapsed": false, |
599 | 599 | "input": [ |
600 | 600 | "f = open('data/austen-emma-excerpt.txt')\n", |
601 | | - "text = f.read()" |
| 601 | + "text = f.read()\n", |
| 602 | + "text" |
602 | 603 | ], |
603 | 604 | "language": "python", |
604 | 605 | "metadata": {}, |
605 | | - "outputs": [], |
606 | | - "prompt_number": 32 |
| 606 | + "outputs": [ |
| 607 | + { |
| 608 | + "output_type": "pyout", |
| 609 | + "prompt_number": 41, |
| 610 | + "text": [ |
| 611 | + "\"Emma by Jane Austen 1816\\n\\nVOLUME I\\n\\nCHAPTER I\\n\\n\\nEmma Woodhouse, handsome, clever, and rich, with a comfortable home\\nand happy disposition, seemed to unite some of the best blessings\\nof existence; and had lived nearly twenty-one years in the world\\nwith very little to distress or vex her.\\n\\nShe was the youngest of the two daughters of a most affectionate,\\nindulgent father; and had, in consequence of her sister's marriage,\\nbeen mistress of his house from a very early period. Her mother\\nhad died too long ago for her to have more than an indistinct\\nremembrance of her caresses; and her place had been supplied\\nby an excellent woman as governess, who had fallen little short\\nof a mother in affection.\\n\\nSixteen years had Miss Taylor been in Mr. Woodhouse's family,\\nless as a governess than a friend, very fond of both daughters,\\nbut particularly of Emma. Between _them_ it was more the intimacy\\nof sisters. Even before Miss Taylor had ceased to hold the nominal\\noffice of governess, the mildness of her temper had hardly allowed\\nher to impose any restraint; and the shadow of authority being\\nnow long passed away, they had been living together as friend and\\nfriend very mutually attached, and Emma doing just what she liked;\\nhighly esteeming Miss Taylor's judgment, but directed chiefly by\\nher own.\\n\"" |
| 612 | + ] |
| 613 | + } |
| 614 | + ], |
| 615 | + "prompt_number": 41 |
607 | 616 | }, |
608 | 617 | { |
609 | 618 | "cell_type": "markdown", |
|
634 | 643 | "---------" |
635 | 644 | ] |
636 | 645 | }, |
| 646 | + { |
| 647 | + "cell_type": "markdown", |
| 648 | + "metadata": {}, |
| 649 | + "source": [ |
| 650 | + "Say we would like to find out what words are used in this small text. We can use the following *function* to split the text into words:" |
| 651 | + ] |
| 652 | + }, |
| 653 | + { |
| 654 | + "cell_type": "code", |
| 655 | + "collapsed": false, |
| 656 | + "input": [ |
| 657 | + "words = text.split()\n", |
| 658 | + "words" |
| 659 | + ], |
| 660 | + "language": "python", |
| 661 | + "metadata": {}, |
| 662 | + "outputs": [ |
| 663 | + { |
| 664 | + "output_type": "pyout", |
| 665 | + "prompt_number": 42, |
| 666 | + "text": [ |
| 667 | + "['Emma',\n", |
| 668 | + " 'by',\n", |
| 669 | + " 'Jane',\n", |
| 670 | + " 'Austen',\n", |
| 671 | + " '1816',\n", |
| 672 | + " 'VOLUME',\n", |
| 673 | + " 'I',\n", |
| 674 | + " 'CHAPTER',\n", |
| 675 | + " 'I',\n", |
| 676 | + " 'Emma',\n", |
| 677 | + " 'Woodhouse,',\n", |
| 678 | + " 'handsome,',\n", |
| 679 | + " 'clever,',\n", |
| 680 | + " 'and',\n", |
| 681 | + " 'rich,',\n", |
| 682 | + " 'with',\n", |
| 683 | + " 'a',\n", |
| 684 | + " 'comfortable',\n", |
| 685 | + " 'home',\n", |
| 686 | + " 'and',\n", |
| 687 | + " 'happy',\n", |
| 688 | + " 'disposition,',\n", |
| 689 | + " 'seemed',\n", |
| 690 | + " 'to',\n", |
| 691 | + " 'unite',\n", |
| 692 | + " 'some',\n", |
| 693 | + " 'of',\n", |
| 694 | + " 'the',\n", |
| 695 | + " 'best',\n", |
| 696 | + " 'blessings',\n", |
| 697 | + " 'of',\n", |
| 698 | + " 'existence;',\n", |
| 699 | + " 'and',\n", |
| 700 | + " 'had',\n", |
| 701 | + " 'lived',\n", |
| 702 | + " 'nearly',\n", |
| 703 | + " 'twenty-one',\n", |
| 704 | + " 'years',\n", |
| 705 | + " 'in',\n", |
| 706 | + " 'the',\n", |
| 707 | + " 'world',\n", |
| 708 | + " 'with',\n", |
| 709 | + " 'very',\n", |
| 710 | + " 'little',\n", |
| 711 | + " 'to',\n", |
| 712 | + " 'distress',\n", |
| 713 | + " 'or',\n", |
| 714 | + " 'vex',\n", |
| 715 | + " 'her.',\n", |
| 716 | + " 'She',\n", |
| 717 | + " 'was',\n", |
| 718 | + " 'the',\n", |
| 719 | + " 'youngest',\n", |
| 720 | + " 'of',\n", |
| 721 | + " 'the',\n", |
| 722 | + " 'two',\n", |
| 723 | + " 'daughters',\n", |
| 724 | + " 'of',\n", |
| 725 | + " 'a',\n", |
| 726 | + " 'most',\n", |
| 727 | + " 'affectionate,',\n", |
| 728 | + " 'indulgent',\n", |
| 729 | + " 'father;',\n", |
| 730 | + " 'and',\n", |
| 731 | + " 'had,',\n", |
| 732 | + " 'in',\n", |
| 733 | + " 'consequence',\n", |
| 734 | + " 'of',\n", |
| 735 | + " 'her',\n", |
| 736 | + " \"sister's\",\n", |
| 737 | + " 'marriage,',\n", |
| 738 | + " 'been',\n", |
| 739 | + " 'mistress',\n", |
| 740 | + " 'of',\n", |
| 741 | + " 'his',\n", |
| 742 | + " 'house',\n", |
| 743 | + " 'from',\n", |
| 744 | + " 'a',\n", |
| 745 | + " 'very',\n", |
| 746 | + " 'early',\n", |
| 747 | + " 'period.',\n", |
| 748 | + " 'Her',\n", |
| 749 | + " 'mother',\n", |
| 750 | + " 'had',\n", |
| 751 | + " 'died',\n", |
| 752 | + " 'too',\n", |
| 753 | + " 'long',\n", |
| 754 | + " 'ago',\n", |
| 755 | + " 'for',\n", |
| 756 | + " 'her',\n", |
| 757 | + " 'to',\n", |
| 758 | + " 'have',\n", |
| 759 | + " 'more',\n", |
| 760 | + " 'than',\n", |
| 761 | + " 'an',\n", |
| 762 | + " 'indistinct',\n", |
| 763 | + " 'remembrance',\n", |
| 764 | + " 'of',\n", |
| 765 | + " 'her',\n", |
| 766 | + " 'caresses;',\n", |
| 767 | + " 'and',\n", |
| 768 | + " 'her',\n", |
| 769 | + " 'place',\n", |
| 770 | + " 'had',\n", |
| 771 | + " 'been',\n", |
| 772 | + " 'supplied',\n", |
| 773 | + " 'by',\n", |
| 774 | + " 'an',\n", |
| 775 | + " 'excellent',\n", |
| 776 | + " 'woman',\n", |
| 777 | + " 'as',\n", |
| 778 | + " 'governess,',\n", |
| 779 | + " 'who',\n", |
| 780 | + " 'had',\n", |
| 781 | + " 'fallen',\n", |
| 782 | + " 'little',\n", |
| 783 | + " 'short',\n", |
| 784 | + " 'of',\n", |
| 785 | + " 'a',\n", |
| 786 | + " 'mother',\n", |
| 787 | + " 'in',\n", |
| 788 | + " 'affection.',\n", |
| 789 | + " 'Sixteen',\n", |
| 790 | + " 'years',\n", |
| 791 | + " 'had',\n", |
| 792 | + " 'Miss',\n", |
| 793 | + " 'Taylor',\n", |
| 794 | + " 'been',\n", |
| 795 | + " 'in',\n", |
| 796 | + " 'Mr.',\n", |
| 797 | + " \"Woodhouse's\",\n", |
| 798 | + " 'family,',\n", |
| 799 | + " 'less',\n", |
| 800 | + " 'as',\n", |
| 801 | + " 'a',\n", |
| 802 | + " 'governess',\n", |
| 803 | + " 'than',\n", |
| 804 | + " 'a',\n", |
| 805 | + " 'friend,',\n", |
| 806 | + " 'very',\n", |
| 807 | + " 'fond',\n", |
| 808 | + " 'of',\n", |
| 809 | + " 'both',\n", |
| 810 | + " 'daughters,',\n", |
| 811 | + " 'but',\n", |
| 812 | + " 'particularly',\n", |
| 813 | + " 'of',\n", |
| 814 | + " 'Emma.',\n", |
| 815 | + " 'Between',\n", |
| 816 | + " '_them_',\n", |
| 817 | + " 'it',\n", |
| 818 | + " 'was',\n", |
| 819 | + " 'more',\n", |
| 820 | + " 'the',\n", |
| 821 | + " 'intimacy',\n", |
| 822 | + " 'of',\n", |
| 823 | + " 'sisters.',\n", |
| 824 | + " 'Even',\n", |
| 825 | + " 'before',\n", |
| 826 | + " 'Miss',\n", |
| 827 | + " 'Taylor',\n", |
| 828 | + " 'had',\n", |
| 829 | + " 'ceased',\n", |
| 830 | + " 'to',\n", |
| 831 | + " 'hold',\n", |
| 832 | + " 'the',\n", |
| 833 | + " 'nominal',\n", |
| 834 | + " 'office',\n", |
| 835 | + " 'of',\n", |
| 836 | + " 'governess,',\n", |
| 837 | + " 'the',\n", |
| 838 | + " 'mildness',\n", |
| 839 | + " 'of',\n", |
| 840 | + " 'her',\n", |
| 841 | + " 'temper',\n", |
| 842 | + " 'had',\n", |
| 843 | + " 'hardly',\n", |
| 844 | + " 'allowed',\n", |
| 845 | + " 'her',\n", |
| 846 | + " 'to',\n", |
| 847 | + " 'impose',\n", |
| 848 | + " 'any',\n", |
| 849 | + " 'restraint;',\n", |
| 850 | + " 'and',\n", |
| 851 | + " 'the',\n", |
| 852 | + " 'shadow',\n", |
| 853 | + " 'of',\n", |
| 854 | + " 'authority',\n", |
| 855 | + " 'being',\n", |
| 856 | + " 'now',\n", |
| 857 | + " 'long',\n", |
| 858 | + " 'passed',\n", |
| 859 | + " 'away,',\n", |
| 860 | + " 'they',\n", |
| 861 | + " 'had',\n", |
| 862 | + " 'been',\n", |
| 863 | + " 'living',\n", |
| 864 | + " 'together',\n", |
| 865 | + " 'as',\n", |
| 866 | + " 'friend',\n", |
| 867 | + " 'and',\n", |
| 868 | + " 'friend',\n", |
| 869 | + " 'very',\n", |
| 870 | + " 'mutually',\n", |
| 871 | + " 'attached,',\n", |
| 872 | + " 'and',\n", |
| 873 | + " 'Emma',\n", |
| 874 | + " 'doing',\n", |
| 875 | + " 'just',\n", |
| 876 | + " 'what',\n", |
| 877 | + " 'she',\n", |
| 878 | + " 'liked;',\n", |
| 879 | + " 'highly',\n", |
| 880 | + " 'esteeming',\n", |
| 881 | + " 'Miss',\n", |
| 882 | + " \"Taylor's\",\n", |
| 883 | + " 'judgment,',\n", |
| 884 | + " 'but',\n", |
| 885 | + " 'directed',\n", |
| 886 | + " 'chiefly',\n", |
| 887 | + " 'by',\n", |
| 888 | + " 'her',\n", |
| 889 | + " 'own.']" |
| 890 | + ] |
| 891 | + } |
| 892 | + ], |
| 893 | + "prompt_number": 42 |
| 894 | + }, |
| 895 | + { |
| 896 | + "cell_type": "markdown", |
| 897 | + "metadata": {}, |
| 898 | + "source": [ |
| 899 | + "By issuing the function split on our text, Python split the text on spaces and returns a `list` or words. A list functions similar to a string. We can access all of its components using indexes and we can use slice indexes to access parts of the list. Let's try it!" |
| 900 | + ] |
| 901 | + }, |
| 902 | + { |
| 903 | + "cell_type": "markdown", |
| 904 | + "metadata": {}, |
| 905 | + "source": [ |
| 906 | + "--------" |
| 907 | + ] |
| 908 | + }, |
| 909 | + { |
| 910 | + "cell_type": "heading", |
| 911 | + "level": 4, |
| 912 | + "metadata": {}, |
| 913 | + "source": [ |
| 914 | + "Quiz!" |
| 915 | + ] |
| 916 | + }, |
| 917 | + { |
| 918 | + "cell_type": "markdown", |
| 919 | + "metadata": {}, |
| 920 | + "source": [ |
| 921 | + "Write a small program that defines a variable `first_word` and assign to it the first word of our text. Play around a little with the indexes to see if you really understand how it works." |
| 922 | + ] |
| 923 | + }, |
| 924 | + { |
| 925 | + "cell_type": "code", |
| 926 | + "collapsed": false, |
| 927 | + "input": [ |
| 928 | + "first_word = # insert your code here\n", |
| 929 | + "print first_word" |
| 930 | + ], |
| 931 | + "language": "python", |
| 932 | + "metadata": {}, |
| 933 | + "outputs": [ |
| 934 | + { |
| 935 | + "output_type": "stream", |
| 936 | + "stream": "stdout", |
| 937 | + "text": [ |
| 938 | + "Emma\n" |
| 939 | + ] |
| 940 | + } |
| 941 | + ], |
| 942 | + "prompt_number": 43 |
| 943 | + }, |
| 944 | + { |
| 945 | + "cell_type": "markdown", |
| 946 | + "metadata": {}, |
| 947 | + "source": [ |
| 948 | + "---------------" |
| 949 | + ] |
| 950 | + }, |
637 | 951 | { |
638 | 952 | "cell_type": "code", |
639 | 953 | "collapsed": false, |
|
0 commit comments