<jupyter_start><jupyter_text>Thus far we have seen the following data types:* integer (counting number) - `int`.* floating point number (number with decimal point) - `float`.* string (text) - `str`.* boolean (True or False value) - `bool`.In data analysis, we often want to collect together several numbers, orstrings, into a *sequence*.  This allows us to collect values together intoone place, and refer to all the values with a single name.  Now that we can refer to all the values with a single name, we can write code that works on the whole sequence at once.For example, remember our problem of the three girls in a family of four.You have seen that we can make four random values, that can be 0 or 1, like this:<jupyter_code># Fetch the "randint" function from the Numpy library.
from numpy.random import randint
# Get four random numbers between 0 and 1.
a = randint(0, 2)
b = randint(0, 2)
c = randint(0, 2)
d = randint(0, 2)<jupyter_output><empty_output><jupyter_text>Here, each random number gets its own variable.   Then we added the numbers like this:<jupyter_code>a + b + c + d<jupyter_output><empty_output><jupyter_text>This gave us the number of girls for one simulated family.Now imagine that we were trying to simulate a family of 12 children.  We wouldhave to give each child their own variable `a` through `l` (small L), and then have a long line like this:```a + b + c + d + e + f + g + h + i + j + k + l```That would be annoying in this case, and impractical when we have to simulatelarger units, such as the 100 members of Robert Swain's jury panel.Sequences are part of the solution to this problem.  Sequences are values that contain zero or more other values.  There are various types of sequences, but the two we will use the most are:* Lists - `list`* Arrays - `np.array`We will see arrays soon.   This page is about *lists*.  Making a listYou make a list using *square brackets* - `[` and `]`.Here we make a list that contains three integers:<jupyter_code>my_numbers = [1, 2, 3]
my_numbers<jupyter_output><empty_output><jupyter_text>`[1, 2, 3]` is a *list expression* because it is a recipe that results ina value that is a list).  We confirm it is an expression by showing that the notebook displays a value:<jupyter_code>[1, 2, 3]<jupyter_output><empty_output><jupyter_text>What kind of value is it?<jupyter_code>type(my_numbers)<jupyter_output><empty_output><jupyter_text>Lists can be empty.  To make an empty list, put nothing inside the square brackets, like this:<jupyter_code>my_empty_list = []
my_empty_list<jupyter_output><empty_output><jupyter_text>A list can have any kind of value as its elements.  For example, here is a list of strings:<jupyter_code>some_strings = ["Captain", "Agent", "Jessica", "Luke"]
some_strings<jupyter_output><empty_output><jupyter_text>Functions and listsPython has some built-in functions that operate on sequences, like lists.One of these is the function `len`.  Here is a *call expression*, using the function `len` on our list:<jupyter_code>len(my_numbers)<jupyter_output><empty_output><jupyter_text>As you might predict, calling `len` with the list as an argument, returns the number of elements in the list.Another function that operates on lists is `sum`.  This adds all the elements in the list together, and returns the result:<jupyter_code>sum(my_numbers)<jupyter_output><empty_output><jupyter_text>Now we have another way of solving the problem of making the family of fourchildren above.  Use Control-Enter a few times on the cell below to convinceyourself it returns numbers between 0 and 4 - simulated numbers of girls ina family of four children.<jupyter_code># Get four random numbers between 0 and 1, put them in a list.
family = [randint(0, 2), randint(0, 2), randint(0, 2), randint(0, 2)]
# Add all the values in the list
sum(family)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.08181818181818182, 'fraction_numerical': 0.009870129870129871, 'mean_word_length': 5.1419457735247205, 'pattern_counts': {'":': 0, '<': 41, '<?xml version=': 0, '>': 41, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '65988', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1194, 'n_tokens_neox': 1135, 'n_words': 536, 'path': 'notebooks/03/lists.ipynb', 'repo_name': 'matthew-brett/cfd-uob', 'size': '3850'}