Skip to content

Commit 90446c5

Browse files
authored
Merge pull request #926
Swapping the order of episodes on lists and loops
2 parents 4f31efa + 1c238df commit 90446c5

File tree

5 files changed

+170
-156
lines changed

5 files changed

+170
-156
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ This lesson is also available in [R][R] and [MATLAB][MATLAB].
3131
| 1 | [Python Fundamentals][episode01] | 30 | What basic data types can I work with in Python?<br>How can I create a new variable in Python?<br>Can I change the value associated with a variable after I create it? |
3232
| 2 | [Analyzing Patient Data][episode02] | 60 | How can I process tabular data files in Python? |
3333
| 3 | [Visualizing Tabular Data][episode03] | 50 | How can I visualize tabular data in Python?<br>How can I group several plots together? |
34-
| 4 | [Repeating Actions with Loops][episode04] | 30 | How can I do the same operations on many different values? |
35-
| 5 | [Storing Multiple Values in Lists][episode05] | 30 | How can I store many values together? |
34+
| 4 | [Storing Multiple Values in Lists][episode04] | 30 | How can I store many values together? |
35+
| 5 | [Repeating Actions with Loops][episode05] | 30 | How can I do the same operations on many different values? |
3636
| 6 | [Analyzing Data from Multiple Files][episode06] | 20 | How can I do the same operations on many different files? |
3737
| 7 | [Making Choices][episode07] | 30 | How can my programs do different things based on data values? |
3838
| 8 | [Creating Functions][episode08] | 30 | How can I define new functions?<br>What’s the difference between defining and calling a function?<br>What happens when I call a function? |
@@ -107,8 +107,8 @@ industry and government. More information can be found [here][cp-about].
107107
[episode01]: https://swcarpentry.github.io/python-novice-inflammation/01-intro/index.html
108108
[episode02]: https://swcarpentry.github.io/python-novice-inflammation/02-numpy/index.html
109109
[episode03]: https://swcarpentry.github.io/python-novice-inflammation/03-matplotlib/index.html
110-
[episode04]: https://swcarpentry.github.io/python-novice-inflammation/04-loop/index.html
111-
[episode05]: https://swcarpentry.github.io/python-novice-inflammation/05-lists/index.html
110+
[episode04]: https://swcarpentry.github.io/python-novice-inflammation/04-lists/index.html
111+
[episode05]: https://swcarpentry.github.io/python-novice-inflammation/05-loop/index.html
112112
[episode06]: https://swcarpentry.github.io/python-novice-inflammation/06-files/index.html
113113
[episode07]: https://swcarpentry.github.io/python-novice-inflammation/07-cond/index.html
114114
[episode08]: https://swcarpentry.github.io/python-novice-inflammation/08-func/index.html

_episodes/05-lists.md renamed to _episodes/04-lists.md

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,17 @@ list[2:9]), in the same way as strings and arrays."
2020
- "Strings are immutable (i.e., the characters in them cannot be changed)."
2121
---
2222

23-
Similar to a string that can contain many characters, a list is a container that can store many
24-
values. Unlike NumPy arrays, lists are built into the language (so we don't have to load a library
25-
to use them).
23+
In the previous episode, we analyzed a single file with inflammation data. Our goal, however, is to
24+
process all the inflammation data we have, which means that we still have eleven more files to go!
25+
26+
The natural first step is to collect the names of all the files that we have to process. In Python,
27+
a list is a way to store multiple values together. In this episode, we will learn how to store
28+
multiple values in a list as well as how to work with lists.
29+
30+
## Python lists
31+
32+
Unlike NumPy arrays, lists are built into the language so we do not have to load a library
33+
to use them.
2634
We create a list by putting values inside square brackets and separating the values with commas:
2735

2836
~~~
@@ -57,22 +65,6 @@ Yes, we can use negative numbers as indices in Python. When we do so, the index
5765
last element in the list, `-2` the second to last, and so on.
5866
Because of this, `odds[3]` and `odds[-1]` point to the same element here.
5967

60-
If we loop over a list, the loop variable is assigned to its elements one at a time:
61-
62-
~~~
63-
for number in odds:
64-
print(number)
65-
~~~
66-
{: .language-python}
67-
68-
~~~
69-
1
70-
3
71-
5
72-
7
73-
~~~
74-
{: .output}
75-
7668
There is one important difference between lists and strings:
7769
we can change the values in a list,
7870
but we cannot change individual characters in a string.
@@ -308,33 +300,6 @@ odds: [1, 3, 5, 7]
308300
~~~
309301
{: .output}
310302
311-
> ## Turn a String Into a List
312-
>
313-
> Use a for-loop to convert the string "hello" into a list of letters:
314-
>
315-
> ~~~
316-
> ['h', 'e', 'l', 'l', 'o']
317-
> ~~~
318-
> {: .language-python}
319-
>
320-
> Hint: You can create an empty list like this:
321-
>
322-
> ~~~
323-
> my_list = []
324-
> ~~~
325-
> {: .language-python}
326-
>
327-
> > ## Solution
328-
> > ~~~
329-
> > my_list = []
330-
> > for char in 'hello':
331-
> > my_list.append(char)
332-
> > print(my_list)
333-
> > ~~~
334-
> > {: .language-python}
335-
> {: .solution}
336-
{: .challenge}
337-
338303
Subsets of lists and strings can be accessed by specifying ranges of values in brackets,
339304
similar to how we accessed ranges of positions in a NumPy array.
340305
This is commonly referred to as "slicing" the list/string.

0 commit comments

Comments
 (0)