Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"Andy Miles"
"Rick Riehle",
"Joseph Schilz",
"Joseph Sheedy"
"Joseph Sheedy",
"Hosung Song"
]

Expand Down
14 changes: 7 additions & 7 deletions source/exercises/kata_fourteen.rst
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ Building the Trigrams dict

So you've got a list of words, and you need to build up a dict like one of the above.

It time to create a python file and start writting some code!
It's time to create a python file and start writting some code!

.. code-block:: python

Expand Down Expand Up @@ -244,7 +244,7 @@ So how do you actually build up that dict? That's kind of the point of the exerc

**Looping through the words**

Obviously you need to loop through all the words, so a ``for loop`` makes sense. However, this is a bit tricky. Usually in Python you loop through all the items in a list, and don't worry about the indices:
Obviously you need to loop through all the words, so a ``for`` loop makes sense. However, this is a bit tricky. Usually in Python you loop through all the items in a list, and don't worry about the indices:

.. code-block:: python

Expand All @@ -256,23 +256,23 @@ So contrary to the usual practice, an index can be helpful here:

.. code-block:: python

for i in len(words)-2: # why -2 ?
for i in range(len(words)-2): # why -2 ?
pair = words[i:i + 2]
follower = words[i + 2]

**Adding a pair to the dict:**

For each pair in the text, you need to add it to the dict. But:

- words[i:i + 2] is a list with two words in it. Can that be used as a key in a dict? (Try it.) If not, how can you make a valid key out of it?
- ``words[i:i + 2]`` is a list with two words in it. Can that be used as a key in a dict? (Try it.) If not, how can you make a valid key out of it?

- As you loop through the text, you will collect pairs of words. Each time, a given pair may already be in the dict.

- If the pair is not in the dict, you want to put it in the dict, with value being a list with the follower in it::

("may", "I"): ["wish"]

- If the pair already is in the dict, then you want to add the follower (the second word in the pair) to the list that's already there
- If the pair already is in the dict, then you want to add the follower (the second word in the pair) to the list that's already there::

("wish", "I"): ["may", "might"]

Expand All @@ -294,7 +294,7 @@ Using the Trigrams dict

This is the fun part. Once you have a mapping of word pairs to following words, you can build up some new "fake" text. Re-read the previous sections again to remind yourself of the procedure. Here are a couple of additional hints and questions to consider:

- The ```random`` module <https://docs.python.org/3/library/random.html#module-random>`_ is your friend here:
- The ``random`` module <https://docs.python.org/3/library/random.html#module-random> is your friend here:

.. code-block:: python

Expand Down Expand Up @@ -357,7 +357,7 @@ Do get the full trigrams code working first, then play with some of the fancier
Code Structure
--------------

Break your code down into a handful of separate functions. This way you can test each on its own, and it's easier to refactor one part without messing with the others. For instance, your __main__ block might look something like:
Break your code down into a handful of separate functions. This way you can test each on its own, and it's easier to refactor one part without messing with the others. For instance, your ``__main__`` block might look something like:

.. code-block:: python

Expand Down
2 changes: 1 addition & 1 deletion source/exercises/mailroom-part2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ In the first version of mailroom, you generated a letter to a donor who had just

In this version of your program, add a function (and a menu item to invoke it), that goes through all the donors in your donor data structure, generates a thank you letter for each donor, and writes each letter to disk as a text file.

Your main menu may look something like:
Your main menu may look something like::

Choose an action:

Expand Down
4 changes: 2 additions & 2 deletions source/modules/DictsAndSets.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ Calling the dict type object constructor:
>>> dict(key1=3, key2= 5)
{'key1': 3, 'key2': 5}

# creating and empty dict, and then populating it:
# creating an empty dict, and then populating it:
>>> d = {}
>>> d['key1'] = 3
>>> d['key2'] = 5
Expand Down Expand Up @@ -181,7 +181,7 @@ Traditionally, dictionaries have had no defined order. See this example from Pyt
Note how I defined the dict in a natural order, but when it gets printed, or you display the keys, they are in a different order.

However, In cPython 3.6, the internal implementation was changed, and it *does* happen to preserve order. In cPython 3.6, that is considered an implementation detail -- and you should not count on it! However, as of cPython 3.7, dictionaries preserving order will be part of the language specification. This was declared by Guido on the python-dev mailing list on
`Dec 15, 2017 <https://mail.python.org/pipermail/python-dev/2017-December/151283.html>`
Dec 15, 2017 <https://mail.python.org/pipermail/python-dev/2017-December/151283.html>.

.. code-block:: ipython

Expand Down
6 changes: 3 additions & 3 deletions source/modules/Files.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ Common Idioms
do_something_with_line()


We will learn more about the keyword with later, but for now, just understand
We will learn more about the keyword ``with`` later, but for now, just understand
the syntax and the advantage over the try-finally block:

.. code-block:: python
Expand Down Expand Up @@ -192,11 +192,11 @@ Absolute paths:
'/home/chris/secret.txt'


Either work with ``open()`` , etc.
Either works with ``open()`` , etc.

(A working directory only makes sense with command-line programs.)

os module
``os`` module
----------

.. code-block:: python
Expand Down