Lecture 8 – Lists and Strings

Data 6, Summer 2021

Lists

We use square brackets to create lists.

Types and comparisons

Working with lists

Append

Containment

Quick Check 1

Indexing

Slicing

Negative indexing

Quick Check 2

Example: While loops with lists

.index

.index tells us the position of an element in a list – if it is in the list.

Example: next day of the week

Strings

Finding characters

Differences between strings and lists

Demo

Let's use data about survivors of the Titanic, downloaded from here.

Soon, we will learn how to load in data like the above and extract columns as lists. But for now, just run the following cell.