[(1,2), (3,4)] is the sequence, a, b are the names each element is being unpacked to
Tags
#python #sicp
Question
What is sequence unpacking?
Answer
?
Tags
#python #sicp
Question
What is sequence unpacking?
Answer
for a,b in [(1,2), (3,4)]
[(1,2), (3,4)] is the sequence, a, b are the names each element is being unpacked to
If you want to change selection, open original toplevel document below and click on "Move attachment"
Parent (intermediate) annotation
Open it This pattern of binding multiple names to multiple values in a fixed-length
sequence is called sequence unpacking; it is the same pattern that we see in
assignment statements that bind multiple names to multiple values.
Original toplevel document
2.3 Sequences wo names in its header will bind each name
x and y to the first and second elements in each pair, respectively.
>>> for x, y in pairs:
if x == y:
same_count = same_count + 1
>>> same_count
2
<span>This pattern of binding multiple names to multiple values in a fixed-length
sequence is called sequence unpacking; it is the same pattern that we see in
assignment statements that bind multiple names to multiple values.
Ranges. A range is another built-in type of sequence in Python, which
represents a range of integers. Ranges are created with range , which takes
two integer arguments: the first
Summary
status
not learned
measured difficulty
37% [default]
last interval [days]
repetition number in this series
0
memorised on
scheduled repetition
scheduled repetition interval
last repetition or drill
Details
No repetitions
Discussion
Do you want to join discussion? Click here to log in or create user.