Skip to content

Commit 895b99a

Browse files
committed
Updated based on feedback
Altered underlying image to represent three rows of four baskets each, and updated text to follow this change. Used 'veg' as the variable name rather than 'x' (I needed something SHORT to keep the graphic from getting too cluttered, so I opted for 'veg' over 'produce' or 'vegetables'); and made minor text changes to align with suggestions for clarity.
1 parent 5bcc8ce commit 895b99a

File tree

7 files changed

+23
-25
lines changed

7 files changed

+23
-25
lines changed

_episodes/04-lists.md

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -161,78 +161,76 @@ does not.
161161
> Since a list can contain any Python variables, it can even contain other lists.
162162
>
163163
> For example, you could represent the products on the shelves of a small grocery shop
164-
> as a nested list called x:
164+
> as a nested list called `veg`:
165165
>
166-
> [![x is represented as a shelf full of produce. There are four rows of vegetables
167-
> on the shelf, and each row contains five baskets of vegetables. We can label
166+
> ![`veg` is represented as a shelf full of produce. There are three rows of vegetables
167+
> on the shelf, and each row contains three baskets of vegetables. We can label
168168
> each basket according to the type of vegetable it contains, so the top row
169-
> contains (from left to right) lettuce, lettuce, peppers, zucchini, squash,
170-
> and basil.](../fig/04_groceries_x.png)]
169+
> contains (from left to right) lettuce, lettuce, and peppers.](../fig/04_groceries_veg.png)
171170
>
172171
> To store the contents of the shelf in a nested list, you write it this way:
173172
>
174173
> ~~~
175-
> x = [['lettuce', 'lettuce', 'peppers', 'zucchini', 'squash', 'basil'],
176-
> ['lettuce', 'lettuce', 'peppers', 'zucchini', 'peppers', 'parsley'],
177-
> ['lettuce', 'cilantro', 'peppers', 'zucchini', 'squash', 'spinach'],
178-
> ['cabbage', 'broccoli', 'asparagus', 'zucchini', 'squash', 'cauliflower']]
174+
> veg = [['lettuce', 'lettuce', 'peppers', 'zucchini'],
175+
> ['lettuce', 'lettuce', 'peppers', 'zucchini'],
176+
> ['lettuce', 'cilantro', 'peppers', 'zucchini']]
179177
> ~~~
180178
> {: .language-python}
181179
>
182-
> Here are some visual examples of how indexing a list of lists `x` works. First,
183-
> you can reference each row on the shelf as a separate list. For example, x[2]
184-
> represents the list of baskets on the third row of the shelf.
180+
> Here are some visual examples of how indexing a list of lists `veg` works. First,
181+
> you can reference each row on the shelf as a separate list. For example, `veg[2]`
182+
> represents the bottom row, which is a list of the baskets in that row.
185183
>
186-
> [![x is now shown as a list of four rows, with x[0] representing the top row of
187-
> five baskets, x[1] representing the second row, x[2] representing the third row,
188-
> and x[3] representing the bottom row.](../fig/04_groceries_x0.png)]
184+
> ![`veg` is now shown as a list of three rows, with `veg[0]` representing the top row of
185+
> three baskets, `veg[1]` representing the second row, and `veg[2]` representing the bottom row.](../fig/04_groceries_veg0.png)
189186
>
190187
> Index operations using the image would work like this:
191188
>
192189
> ~~~
193-
> print(x[2])
190+
> print(veg[2])
194191
> ~~~
195192
> {: .language-python}
196193
>
197194
> ~~~
198-
> ['lettuce', 'cilantro', 'peppers', 'zucchini', 'squash', 'spinach']
195+
> ['lettuce', 'cilantro', 'peppers', 'zucchini']
199196
> ~~~
200197
> {: .output}
201198
>
202199
> ~~~
203-
> print(x[0])
200+
> print(veg[0])
204201
> ~~~
205202
> {: .language-python}
206203
>
207204
> ~~~
208-
> ['lettuce', 'lettuce', 'peppers', 'zucchini', 'squash', 'basil']
205+
> ['lettuce', 'lettuce', 'peppers', 'zucchini']
209206
> ~~~
210207
> {: .output}
211208
>
212209
> To reference a specific basket on a specific shelf, you use two indexes. The first
213210
> index represents the row (from top to bottom) and the second index represents
214211
> the specific basket (from left to right).
215-
> [![x is now shown as a two-dimensional grid, with each basket labeled according to
212+
> ![`veg` is now shown as a two-dimensional grid, with each basket labeled according to
216213
> its index in the nested list. The first index is the row number and the second
217-
> index is the basket number, so x[1][4] represents the basket on the far right
218-
> side of the second row (basket 4 on row 1): parsley](../fig/04_groceries_x00.png)]
214+
> index is the basket number, so `veg[1][3]` represents the basket on the far right
215+
> side of the second row (basket 4 on row 2): zucchini](../fig/04_groceries_veg00.png)
219216
>
220217
> ~~~
221-
> print(x[0][0])
218+
> print(veg[0][0])
222219
> ~~~
223220
> {: .language-python}
224221
>
225222
> ~~~
226223
> 'lettuce'
227224
> ~~~
225+
> {: .output}
228226
>
229227
> ~~~
230-
> print(x[3][2])
228+
> print(veg[1][2])
231229
> ~~~
232230
> {: .language-python}
233231
>
234232
> ~~~
235-
> 'asparagus'
233+
> 'peppers'
236234
> ~~~
237235
> {: .output}
238236
>

fig/04_groceries_veg.png

710 KB
Loading

fig/04_groceries_veg0.png

671 KB
Loading

fig/04_groceries_veg00.png

564 KB
Loading

fig/04_groceries_x.png

-619 KB
Binary file not shown.

fig/04_groceries_x0.png

-623 KB
Binary file not shown.

fig/04_groceries_x00.png

-565 KB
Binary file not shown.

0 commit comments

Comments
 (0)