diff --git a/pip2/scripts/session_codes.py b/pip2/scripts/session_codes.py index d892ef6fd..1dd01132d 100644 --- a/pip2/scripts/session_codes.py +++ b/pip2/scripts/session_codes.py @@ -46,7 +46,10 @@ def get_codes(fnames): sessions[14] = ["Prediction/intro-prediction.rst", "Prediction/hangman_guesser.rst", "Prediction/rule-based.rst", "Prediction/shannon_guesser.rst", "Prediction/training.rst", "Prediction/evaluation.rst"] sessions[15] = ["PythonModules/intro-ModulesandGettingHelp.rst", "PythonModules/Therandommodule.rst", "PythonModules/Glossary.rst", "PythonModules/Exercises.rst"] sessions[16] = ["StringFormatting/intro-PrintinginPython2.7.rst", "StringFormatting/Interpolation.rst", "StringFormatting/CSV.rst", "StringFormatting/Exercises.rst"] - +sessions[17] = ["RESTAPIs/intro.rst", "RESTAPIs/RequestURLs.rst", "RESTAPIs/jsonlib.rst", "RESTAPIs/unicode.rst", "RESTAPIs/flickr.rst"] +sessions[18] = ["Classes/intro-ClassesandObjectstheBasics.rst", "Classes/ObjectsRevisited.rst", "Classes/UserDefinedClasses.rst", "Classes/ImprovingourConstructor.rst", "Classes/AddingOtherMethodstoourClass.rst", "Classes/ObjectsasArgumentsandParameters.rst", "Classes/ConvertinganObjecttoaString.rst", "Classes/InstancesasReturnValues.rst", "Classes/sorting_instances.rst", "Classes/Glossary.rst", "Classes/Exercises.rst"] +sessions[19] = ["Assignments/session21.rst"] +sessions[20] = [] f = open('session_codes.txt', 'w') g = open('json_sessin_codes.txt', 'w') diff --git a/pip2/source/AdvancedAccumulation/exercises.rst b/pip2/source/AdvancedAccumulation/exercises.rst new file mode 100644 index 000000000..e43929b8a --- /dev/null +++ b/pip2/source/AdvancedAccumulation/exercises.rst @@ -0,0 +1,161 @@ +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + +Exercises +--------- + + +Write equivalent code using map instead of the manual accumulation below + +.. activecode:: map_exercise_1 + + things = [3, 5, -4, 7] + + accum = [] + for thing in things: + accum.append(thing+1) + print accum + +Use manual accumulation to define the lengths function below. + +.. activecode:: map_exercise_2 + + def lengths(strings): + """lengths takes a list of strings as input and returns a list of numbers that are the lengths + of strings in the input list. Use manual accumulation!""" + # fill in this function's definition to make the test pass. + + import test + test.testEqual(lengths(["Hello", "hi", "bye"]), [5, 2, 3]) + + +Now define lengths using map instead. + +.. activecode:: map_exercise_3 + + def lengths(strings): + """lengths takes a list of strings as input and returns a list of numbers that are the lengths + of strings in the input list. Use map!""" + # fill in this function's definition to make the test pass. + + import test + test.testEqual(lengths(["Hello", "hi", "bye"]), [5, 2, 3]) + +Now define lengths using a list comprehension instead. + +.. activecode:: listcomp_exercise_1 + + def lengths(strings): + """lengths takes a list of strings as input and returns a list of numbers that are the lengths + of strings in the input list. Use a list comprehension!""" + # fill in this function's definition to make the test pass. + + import test + test.testEqual(lengths(["Hello", "hi", "bye"]), [5, 2, 3]) + + +.. activecode:: filter_1 + + things = [3, 5, -4, 7] + # write code to produce a list of only the positive things, [3, 5, 7], via manual accumulation + +.. activecode:: filter_2 + + things = [3, 5, -4, 7] + # write code to produce a list of only the positive things, [3, 5, 7], via manual accumulation + +# define longwords using manual accumulation + +.. activecode:: filter_3 + + def longwords(strings): + """Return a shorter list of strings containing only the strings with more than four characters. Use manual accumulation.""" + # write your code here + + import test + test.testEqual(longwords(["Hello", "hi", "bye", "wonderful"]), ["Hello", "wonderful"]) + +# define longwords using filter + +.. activecode:: filter_4 + + def longwords(strings): + """Return a shorter list of strings containing only the strings with more than four characters. Use the filter function.""" + # write your code here + + import test + test.testEqual(longwords(["Hello", "hi", "bye", "wonderful"]), ["Hello", "wonderful"]) + +# define longwords using a list comprehension + +.. activecode:: listcomp_exercise_2 + + def longwords(strings): + """Return a shorter list of strings containing only the strings with more than four characters. Use a list comprehension.""" + # write your code here + + import test + test.testEqual(longwords(["Hello", "hi", "bye", "wonderful"]), ["Hello", "wonderful"]) + + +Now combine lengths with longwords to make a function that returns the lengths of those strings that have at least 4 characters. Try it first with a list comprehension. + +.. activecode:: listcomp_exercise_3 + + def longlengths(strings): + return None + + import test + test.testEqual(longlengths(["Hello", "hi", "bye", "wonderful"]), [5, 9]) + +Now try doing it using map and filter. + +.. activecode:: listcomp_exercise_4 + + def longlengths(strings): + return None + + import test + test.testEqual(longlengths(["Hello", "hi", "bye", "wonderful"]), [5, 9]) + +Write a function that takes a list of numbers and returns the sum of the squares of all the numbers. First try it using an accumulator pattern. + +.. activecode:: reduce_exercise_2 + + def sumSquares(L): + return None + + nums = [3, 2, 2, -1, 1] + + import test + test.testEqual(sumSquares(nums), 19) + +Now, try it using map and sum + +.. activecode:: reduce_exercise_3 + + def sumSquares(L): + return None + + nums = [3, 2, 2, -1, 1] + + import test + test.testEqual(sumSquares(nums), 19) + + +Finally, try doing it using reduce + +.. activecode:: reduce_exercise_3 + + def sumSquares(L): + return None + + nums = [3, 2, 2, -1, 1] + + import test + test.testEqual(sumSquares(nums), 19) \ No newline at end of file diff --git "a/pip2/source/Sequences/listcomprehensions.rst\\Filter.rst" b/pip2/source/AdvancedAccumulation/filter.rst similarity index 85% rename from "pip2/source/Sequences/listcomprehensions.rst\\Filter.rst" rename to pip2/source/AdvancedAccumulation/filter.rst index 03297d3a8..d34a829a2 100644 --- "a/pip2/source/Sequences/listcomprehensions.rst\\Filter.rst" +++ b/pip2/source/AdvancedAccumulation/filter.rst @@ -1,5 +1,4 @@ -.. Copyright (C) Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris - Meyers, and Dario Mitchell. Permission is granted to copy, distribute +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being Forward, Prefaces, and @@ -33,4 +32,6 @@ Again, this pattern of computation is so common that python offers a more compac print keep_odds([3, 4, 6, 7, 0, 1]) -Now try the filter exercises in session22.py +Exercises +--------- + diff --git a/pip2/source/AdvancedAccumulation/intro.rst b/pip2/source/AdvancedAccumulation/intro.rst new file mode 100644 index 000000000..c860f785b --- /dev/null +++ b/pip2/source/AdvancedAccumulation/intro.rst @@ -0,0 +1,20 @@ +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + +.. _list_comp_chap: + +Introduction: Map, Filter, Reduce and List Comprehensions +========================================================= + +Let's revisit the :ref:`accumulator pattern `. We have frequently taken a list and produced another list from it that contains either a subset of the items or a transformed version of each item. When each item is transformed we say that the operation is a **mapping, or just a map** of the original list. When some items are omitted, we call it a **filter**. + +Python provides built-in functions ``map`` and ``filter``. Python also provides a new syntax, called **list comprehensions**, that lets you express a mapping and/or filtering operation. Just as with named functions and lambda expressions, some students seem to find it easier to think in terms of the map and filter functions, while other students find it easier to read and write list comprehensions. You'll learn both ways; one may even help you understand the other. Most python programmers use list comprehensions, so make sure you learn to read those. In this course, you can choose to learn to write list comprehensions or to use map and filter, whichever you prefer. You should learn to read both list comprehensions and map/filter. + +Other common accumulator patterns on lists ``reduce`` or aggregate all the values into a single value. + +Map, filter, and reduce are commands that you would use in high-performance computing on big datasets. See `MapReduce on Wikipedia `_. diff --git a/pip2/source/AdvancedAccumulation/listcomp.rst b/pip2/source/AdvancedAccumulation/listcomp.rst new file mode 100644 index 000000000..ef024b86b --- /dev/null +++ b/pip2/source/AdvancedAccumulation/listcomp.rst @@ -0,0 +1,73 @@ +.. Copyright (C) Paul Resnick Brad. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + +List Comprehensions +------------------- + +Python provides an alternative way to do map and filter operations, called a **list comprehension**. Many programmers find them easier to understand and write. List comprehensions are concise ways to create lists from other lists. The general syntax is:: + + [ for in if ] + +where the if clause is optional. For example, + +.. activecode:: listcomp_7 + + things = [2, 5, 9] + + yourlist = [value * 2 for value in things] + + print yourlist + +The expression is ``value * 2``. The item variable is ``value`` and the sequence is ``things``. This is an alternative way to perform a mapping operation. As with ``map``, each item in the sequence is transformed into an item in the new list. Instead of the iteration happening automatically, however, we have adopted the syntax of the for loop which may make it easier to understand. + +Just as in a regular for loop, the part of the statement ``for value in things`` says to execute some code once for each item in things. Each time that code is executed, ``value`` is bound to one item from ``things``. The code that is executed each time is the expression at the beginning, ``value * 2``, rather than a block of code indented underneath the for statement. The other difference from a regular for loop is that each time the expression is evaluated, the resulting value is appended to a list. That happens automatically, without the programmer explicitly initializing an empty list or appending each item. + +The ``if`` clause of a list comprehension can be used to do a filter operation. To perform a pure filter operation, the expression can be simply the variable that is bound to each item. For example, the following list comprehension will keep only the positive numbers from the original list. + +.. activecode:: listcomp_8 + + def keep_evens(nums): + new_list = [num for num in nums if num % 2 == 0] + return new_list + + print keep_evens([3, 4, 6, 7, 0, 1]) + +You can also combine map and filter operations by chaining them together, or with a single list comprehension. + +.. activecode:: listcomp_9 + + things = [3, 4, 6, 7, 0, 1 + #chaining together filter and map: + # first, filter to keep only the even numbers + # double each of them + print map(lambda x: x*2, filter(lambda y: y % 2 == 0, things)) + + # equivalent version using list comprehension + print [x*2 for x in things if x % 2 == 0] + + +**Check your understanding** + +.. mchoicemf:: test_question9_20_1 + :answer_a: [4,2,8,6,5] + :answer_b: [8,4,16,12,10] + :answer_c: 10 + :answer_d: [10]. + :correct: d + :feedback_a: Items from alist are doubled before being placed in blist. + :feedback_b: Not all the items in alist are to be included in blist. Look at the if clause. + :feedback_c: The result needs to be a list. + :feedback_d: Yes, 5 is the only odd number in alist. It is doubled before being placed in blist. + + What is printed by the following statements? + + .. code-block:: python + + alist = [4,2,8,6,5] + blist = [num*2 for num in alist if num%2==1] + print blist diff --git "a/pip2/source/Sequences/listcomprehensions.rst\\.rst" b/pip2/source/AdvancedAccumulation/map.rst similarity index 58% rename from "pip2/source/Sequences/listcomprehensions.rst\\.rst" rename to pip2/source/AdvancedAccumulation/map.rst index c4163a8b3..86c900ea9 100644 --- "a/pip2/source/Sequences/listcomprehensions.rst\\.rst" +++ b/pip2/source/AdvancedAccumulation/map.rst @@ -1,5 +1,4 @@ -.. Copyright (C) Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris - Meyers, and Dario Mitchell. Permission is granted to copy, distribute +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being Forward, Prefaces, and @@ -7,12 +6,6 @@ the license is included in the section entitled "GNU Free Documentation License". -Introduction: Map, Filter, and List Comprehensions -================================================== - -Let's revisit the :ref:`accumulator pattern `. We have frequently taken a list and produced another list from it that contains either a subset of the items or a transformed version of each item. When each item is transformed we say that the operation is a **mapping, or just a map** of the original list. When some items are omitted, we call it a **filter**. - -Python provides built-in functions ``map`` and ``filter``. Python also provides a new syntax, called **list comprehensions**, that lets you express a mapping and/or filtering operation. Just as with named functions and lambda expressions, some students seem to find it easier to think in terms of the map and filter functions, while other students find it easier to read and write list comprehensions. You'll learn both ways; one may even help you understand the other. Most python programmers use list comprehensions, so make sure you learn to read those; you can choose to learn to write list comprehensions or to use map and filter, whichever you prefer. Map --- @@ -34,7 +27,7 @@ The following function produces a new list with each item in the original list d things = doubleStuff(things) print things -The doubleStuff function is an example of the accumulator pattern. On line 3, new_list is initialized. On line 5, the doubled value for the current item is produced and on line 6 it is appended to the list we're accumulating. Line 7 executes after we've process all the items in the original list: it returns the new_list. Once again, codelens helps us to see the actual references and objects as they are passed and returned. +The doubleStuff function is an example of the accumulator pattern, in particular the mapping pattern. On line 3, new_list is initialized. On line 5, the doubled value for the current item is produced and on line 6 it is appended to the list we're accumulating. Line 7 executes after we've processrf all the items in the original list: it returns the new_list. Once again, codelens helps us to see the actual references and objects as they are passed and returned. .. codelens:: listcomp_2 @@ -78,13 +71,9 @@ Of course, once we get used to using the map function, it's no longer necessary things = [2, 5, 9] - things4 = map(lambda value: 4*value, things) + things4 = map((lambda value: 4*value), things) print things4 # or all on one line - print map(lambda value: 5*value, [1, 2, 3]) - -.. note:: - - There are some problems with the implementation of the map function in this online environment. So take a look at the exercises in the file session22.py + print map((lambda value: 5*value), [1, 2, 3]) diff --git "a/pip2/source/Sequences/listcomprehensions.rst\\ListComprehensions.rst" b/pip2/source/AdvancedAccumulation/reduce.rst similarity index 55% rename from "pip2/source/Sequences/listcomprehensions.rst\\ListComprehensions.rst" rename to pip2/source/AdvancedAccumulation/reduce.rst index 770990c31..ac6c28f84 100644 --- "a/pip2/source/Sequences/listcomprehensions.rst\\ListComprehensions.rst" +++ b/pip2/source/AdvancedAccumulation/reduce.rst @@ -1,5 +1,4 @@ -.. Copyright (C) Brad Miller, David Ranum, Jeffrey Elkner, Peter Wentworth, Allen B. Downey, Chris - Meyers, and Dario Mitchell. Permission is granted to copy, distribute +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or any later version published by the Free Software Foundation; with Invariant Sections being Forward, Prefaces, and @@ -7,73 +6,6 @@ the license is included in the section entitled "GNU Free Documentation License". -List Comprehensions -------------------- - -Python provides an alternative way to do map and filter operations, called a **list comprehension**. Many programmers find them to understand and write. List comprehensions are concise ways to create lists from other lists. The general syntax is:: - - [ for in if ] - -where the if clause is optional. For example, - -.. activecode:: listcomp_7 - - things = [2, 5, 9] - - yourlist = [value * 2 for value in things] - - print yourlist - -The expression is ``value * 2``. The item variable is ``value`` and the sequence is ``things``. This is an alternative way to perform a mapping operation. As with ``map``, each item in the sequence is transformed into an item in the new list. Instead of the iteration happening automatically, however, we have adopted the syntax of the for loop which may make it easier to understand. - -Just as in a regular for loop, the part of the statement ``for value in things`` says to execute some code once for each item in things. Each time that code is executed, ``value`` is bound to one item from ``things``. The code that is executed each time is the expression at the beginning, ``value * 2``, rather than a block of code indented underneath the for statement. The other difference from a regular for loop is that each time the expression is evaluated, the resulting value is appended to a list. That happens automatically, without the programmer explicitly initializing an empty list or appending each item. - -The ``if`` clause of a list comprehension can be used to do a filter operation. To perform a pure filter operation, the expression can be simply the variable that is bound to each item. For example, the following list comprehension will keep only the positive numbers from the original list. - -.. activecode:: listcomp_8 - - def keep_evens(nums): - new_list = [num for num in nums if num % 2 == 0] - return new_list - - print keep_evens([3, 4, 6, 7, 0, 1]) - -You can also combine map and filter operations by chaining them together, or with a single list comprehension. - -.. activecode:: listcomp_9 - - things = [3, 4, 6, 7, 0, 1 - #chaining together filter and map: - # first, filter to keep only the even numbers - # double each of them - print map(lambda x: x*2, filter(lambda y: y % 2 == 0, things)) - - # equivalent version using list comprehension - print [x*2 for x in things if x % 2 == 0] - - -**Check your understanding** - -.. mchoicemf:: test_question9_20_1 - :answer_a: [4,2,8,6,5] - :answer_b: [8,4,16,12,10] - :answer_c: 10 - :answer_d: [10]. - :correct: d - :feedback_a: Items from alist are doubled before being placed in blist. - :feedback_b: Not all the items in alist are to be included in blist. Look at the if clause. - :feedback_c: The result needs to be a list. - :feedback_d: Yes, 5 is the only odd number in alist. It is doubled before being placed in blist. - - What is printed by the following statements? - - .. code-block:: python - - alist = [4,2,8,6,5] - blist = [num*2 for num in alist if num%2==1] - print blist - -Now try the list comprehension exercises in session22.py Reduce ====== diff --git a/pip2/source/AdvancedAccumulation/zip.rst b/pip2/source/AdvancedAccumulation/zip.rst new file mode 100644 index 000000000..78a387a0a --- /dev/null +++ b/pip2/source/AdvancedAccumulation/zip.rst @@ -0,0 +1,13 @@ +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + + +Zip +--- + +This section will be forthcoming soon (probably on Tuesday). \ No newline at end of file diff --git a/pip2/source/Assignments/ps11.rst b/pip2/source/Assignments/ps11.rst new file mode 100644 index 000000000..5ecb2dd12 --- /dev/null +++ b/pip2/source/Assignments/ps11.rst @@ -0,0 +1,63 @@ +:orphan: + +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + +.. highlight:: python + :linenothreshold: 500 + + +Week 11: ends November 16 +========================= + +1. Do the multiple choice questions and exercises in the textbook chapters, including the ones at the bottom of the chapters, below the glossary. Don't forget to click Save for each of the exercises, and always access the textbook by clicking on the link from cTools, so that you'll be logged in. + + * Before Tuesday's class: + * View slides ``FB Graph API`` in cTools resources/Slides + * Install pip, and use pip to install the requests module and facebook-sdk module (instructions in the slides) + * Do the :ref:`session 21 exercises `. + * Read the tutorial on GitHub. You will not need to create or use a github repository for this course, but this will help prepare you for the reading and reading response for Wednesday and some later chapters in the Weber book. + + * `Part I `_ + * `Part II `_ + + * Before Thursday's class: + * Read :ref:`List comprehensions` and do the exercises in the chapter (coming soon) + +#. Reading responses + + * By Wednesday midnight: + * Read *The Success of Open Source*, Chapter 3 + * :ref:`Reading response 10 ` + +#. Problem set + + * This week, there will be a file called ps10.py. You should download a copy of it. You will edit it on your laptop or workstation and test it by running it using your native Python interpreter. + * If you put ps10.py in a different directory than ps7.py, you will also need to download a copy of test.py into the directory where you put ps10.py. + +Reading Response +---------------- + +.. _reading_response_10: + +Answer the following questions. + +1. The linux project uses git to organize the work of all the contributors. Take a look at the `linux project on github `_. Take a look at the recent commits. Click around to see how many people have made contributions recently. Also check out the github page for `Runestone `_ and for `my fork of it `_ to make this online textbook. Report on something interesting you found from exploring these public git repositories. + +#. Brooks make an argument that communication complexity grows with the square of the number of people participating in a project. Why might that be true? And what are the things you could do in organizing a project to make it not be true? + +#. What material from the chapter would you like to discuss in class? + +.. activecode:: rr_10_1 + + # Fill in your response in between the triple quotes + s = """ + + """ + print s + diff --git a/pip2/source/Assignments/session21.rst b/pip2/source/Assignments/session21.rst new file mode 100644 index 000000000..e888ef4db --- /dev/null +++ b/pip2/source/Assignments/session21.rst @@ -0,0 +1,64 @@ +:orphan: + +.. Copyright (C) Paul Resnick. Permission is granted to copy, distribute + and/or modify this document under the terms of the GNU Free Documentation + License, Version 1.3 or any later version published by the Free Software + Foundation; with Invariant Sections being Forward, Prefaces, and + Contributor List, no Front-Cover Texts, and no Back-Cover Texts. A copy of + the license is included in the section entitled "GNU Free Documentation + License". + +.. highlight:: python + :linenothreshold: 500 + + +.. _session_21_exercises: + +Session 21 prep +--------------- + +.. mchoicemf:: session21_1 + :answer_a: EDT + :answer_b: GMT + :answer_c: Ann Arbor + :answer_d: en_US + :correct: d + :feedback_a: + :feedback_b: + :feedback_c: + :feedback_d: + + Use the `Facebook Graph explorer `_ and run a GET request on /me. In the results, what is the value associated with the "locale" key? + +.. mchoicemf:: session21_3 + :answer_a: The Facebook server is temporarily not working + :answer_b: Facebook only accepts REST API calls accompanied by an authorization key + :answer_c: The ? is in the wrong place + :answer_d: 245188182322906 is not an object that FB recognizes + :correct: b + :feedback_a: Even when the server is working, it won't provide data in response to a request unless it is accompanied by an authorization key + :feedback_b: The authorization key is normally acquired through the oauth protocol, though we will work around that by copying and pasting it from the FB Graph Explorer https://developers.facebook.com/tools/explorer + :feedback_c: The ? is in the right place, according to the FB Graph API documentation https://developers.facebook.com/docs/graph-api/using-graph-api + :feedback_d: That's actually the id for the FB group for our class. + + Last week, you learned how to call REST APIs using urllib2.urlopen. What happens when you try to invoke the FB API using urllib2.urlopen? Try uncommenting and executing line 9 from session21.py. Also try visiting the URL https://graph.facebook.com/?269032479960344 in your browser. What do you think is going on? + + +.. mchoicema:: session21_4 + :answer_a: You would like your code to be compressed so that it uses less space on your file system + :answer_b: You would like to be able to see or revert to any past version of any of the files in your project + :answer_c: You want to collaborate with others, working in parallel on a project and merging your changes together occasionally + :answer_d: You would like your code to automatically be checked for syntax errors + :answer_e: You would like to distribute your code in a public repository that others can easily fork or comment on + :correct: b,c,e + :feedback_a: If you just want compression, use one of the compression programs like gzip or compress. + :feedback_b: git makes all of your past saved versions accessible. + :feedback_c: git lets multiple work independently on files. If you work on separate parts of a file, it will merge them automatically. If two people edit the same line, then git will mark where there are conflicts and you can resolve them manually. + :feedback_d: There are programs like lint that automatically check for syntax and coding style errors, but they are not an integral part of revision control system. + :feedback_e: Sites like github, bitbucket, and assembla provide a way to publicly share repositories. + + Which of the following are reasons to use a version control system like github? + + + + \ No newline at end of file diff --git a/pip2/source/Classes/sorting_instances.rst b/pip2/source/Classes/sorting_instances.rst index 93f681606..c982807b4 100644 --- a/pip2/source/Classes/sorting_instances.rst +++ b/pip2/source/Classes/sorting_instances.rst @@ -18,7 +18,7 @@ Sorting Lists of Instances ========================== -You previously learned :ref:`how to sort lists `. Sorting lists of instances of a class is not fundamentally different from sorting lists of objects of any other type. There is a way to define a default sort order for instances, right in the class definition, but it requires defining a bunch of methods or one complicated method, so we won't bother with that. Instead, you should just provide a key function as a parameter to sorted (or sort). +You previously learned :ref:`how to sort lists `. Sorting lists of instances of a class is not fundamentally different from sorting lists of objects of any other type. There is a way to define a default sort order for instances, right in the class definition, but it requires defining a bunch of methods or one complicated method, so we won't bother with that. Instead, you should just provide a key function as a parameter to sorted (or sort). Previously, you have seen how to provide such a function when sorting lists of other kinds of objects. For example, given a list of strings, you can sort them in ascending order of their lengths by passing a key parameter. Note that if you refer to a function by name, you give the name of the function without parentheses after it, because you want the function object itself. The sorted function will take care of calling the function, passing the current item in the list. Thus, in the example below, we write ``key=len`` and not ``key=len()``. diff --git a/pip2/source/toc.rst b/pip2/source/toc.rst index d44d92eb0..700acb66a 100644 --- a/pip2/source/toc.rst +++ b/pip2/source/toc.rst @@ -9,6 +9,7 @@ Assignments .. toctree:: :maxdepth: 1 + Assignments/ps11.rst Assignments/ps10.rst Assignments/ps9.rst Assignments/ps8.rst @@ -335,6 +336,20 @@ Classes Classes/Glossary.rst Classes/Exercises.rst +More on Accumulation: Map, Filter, Reduce, List Comprehensions, and Zip +::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: + +.. toctree:: + :maxdepth: 2 + + AdvancedAccumulation/intro.rst + AdvancedAccumulation/map.rst + AdvancedAccumulation/filter.rst + AdvancedAccumulation/listcomp.rst + AdvancedAccumulation/reduce.rst + AdvancedAccumulation/zip.rst + AdvancedAccumulation/exercises.rst + Debugging :::::::::