11-Sequences 4pp
11-Sequences 4pp
Nested lists
>>> pairs = [[10, 20], [30, 40]]
['Demo'] >>> pairs[1]
[30, 40]
>>> pairs[1][0]
30
4
Containers
(Demo)
Sequence Iteration
if element == value:
total = total + 1
return total
(Demo)
8
For Statement Execution Procedure Sequence Unpacking in For Statements
A sequence of
for <name> in <expression>: fixed-length sequences
<suite>
>>> pairs = [[1, 2], [2, 2], [3, 2], [4, 4]]
>>> same_count = 0
1. Evaluate the header <expression>, which must yield an iterable value (a sequence)
>>> same_count
2
9 10
range(-2, 2)
Ranges Length: ending value - starting value
(Demo)
Element selection: starting value + index
['d', 'e', 'm', 'o'] B. If <filter exp> evaluates to a true value, then add the value of <map exp>
to the result list
14
First in Line
16