@@ -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 inflammation data we've got, 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 don't have to load a library
33+ to use them.
2634We 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
5765last element in the list, ` -2 ` the second to last, and so on.
5866Because 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-
7668There is one important difference between lists and strings:
7769we can change the values in a list,
7870but 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-
338303Subsets of lists and strings can be accessed by specifying ranges of values in brackets,
339304similar to how we accessed ranges of positions in a NumPy array.
340305This is commonly referred to as "slicing" the list/string.
0 commit comments