Python learn 04 Lists
Python learn 04 Lists
Chapter 4
Programming
• Algorithm
- A set of rules or steps used to solve a problem
• Data Structure
- A particular way of organizing data in a computer
https://en.wikipedia.org/wiki/Algorithm
https://en.wikipedia.org/wiki/Data_structure
What is Not a “Collection”?
Most of our variables have one value in them - when we put a new
value in the variable, the old value is overwritten
$ python
>>> x = 2
>>> x = 4
>>> print(x)
4
A List is a Kind of
Collection
• A collection allows us to put many values in a single “variable”
Just like strings, we can get at any single element in a list using an
index specified in square brackets
words = line.split()
email = words[1]
print pieces[1]
The Double Split Pattern
words = line.split()
email = words[1] stephen.marquard@uct.ac.za
print pieces[1]
The Double Split Pattern
words = line.split()
email = words[1] stephen.marquard@uct.ac.za
pieces = email.split('@') ['stephen.marquard', 'uct.ac.za']
print pieces[1]