You are on page 1of 2

Lists_Motivation

Ibrahim Abou-Faycal

#
EECE-231
#
Introduction to Computation & Programming with Applications
#
Lists - Motivation

Reading: [Guttag, Sections 5.1, 5.2, and 5.3] Material in these slides is based on
• Slides of EECE-230C & EECE-230 MSFEA, AUB
• [Guttag, Chapter 5]

0.1 Motivation
• Using what we know so far (scalar types, selection, and repetition), we can solve problems
such as: given a sequence of numbers, find sum, average, max, etc
• But can’t solve other basic problems such as: given a sequence of numbers entered by user,
• Print them in reverse order
• Check if they are distinct
• Sort them
• In all such problems, we need to store the whole sequence in memory and manipulate it
• To do that we need lists
• We will also study tuples and strings

0.2 Lists
• List is a built-in type: a mutable ordered sequence of values
– mutable: can be modified
– ordered sequence: each value is identified by an index

1
[ ]: L = [10, 2, "ab", 4.4]
print(L)
L[1] = 7
print(L)
print(L[0])
print(len(L))

Visualization using http://www.pythontutor.com/live.html#mode=edit

You might also like