Lists allow storing values, recalling or changing values or searching for values from the list. They can be used with any kind of data: numbers, text or even content such as images. Table 5.1 lists some of these commands, and Code Example 5.1 shows how they are used. As the examples illustrate, list values are indexed: The first value is stored in the first position, the second value is stored in the second position and so on. (Note how Python and R differ: In Python the first position is located at 0, whereas in R it is 1.) Therefore, lists are not unstructured variable piles, but they have structure. Lists are ordered and store items in the same order they have been added to the list. Thus, the list item in the first index is the item added first to the list.
Beyond accessing single values stored in lists, one can use the for-loop structure to go through all the values stored in the list. Code Example 5.2 illustrates how to multiply all variables stored in a list and print them. This type of approach could be used together with different gatherers, flag variables or other approaches to produce complex algorithms for content filtering. For example, the selection of tweets for further analysis (Code Examples 3.1) showed examples of how to use a for-statement in this way.
The list-related code might look familiar to you. It bears a similarity with how we managed text data. When we split the text based on some characters (e.g. in network analysis we split text by â-â), we actually produced a list containing text segments. Similarly, the text itself is stored in many programming languages as a list of characters. Thus, when accessing the first character from the text we used the same approach as we would use to access the first item from a list. For example, Code Example 5.3 shows how we would select only people whose names start with an A, working on name as a list.