Chapter 10: Tuples Flashcards

1
Q

A type where one value can be checked to see if it is greater than, less than, or equal to another value of the same type. Can be put in a list and sorted.

A

comparable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A collection of related values, often organized in lists, dictionaries, tuples, etc.

A

data structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

A pattern that involves building a list of tuples, sorting, and extracting part of the result.

A

DSU

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

The operation of assembling a variable-length argument tuple.

A

gather/
tuple packing

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

A type that has a hash function. Immutable types like integers, floats, and strings are this; mutable types like lists and dictionaries are not.

A

hashable

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

The operation of treating a sequence as a list of arguments.

A

scatter

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

A summary of the type, size, and composition of a data structure.

A

shape
(of a data structure)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

A list (or other sequence) with a single element.

A

singleton

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

An immutable sequence of elements.
Can be any type
Indexed by integers and can be sliced
Comparable and hashable (can sort lists of them and use as key values in dictionaries)

A

tuple

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

A technique where a sequence on the right is assigned to multiple variables on the left at the same time. The right side is evaluated and then its elements are assigned to the variables on the left.
Also works with lists that have same number of items

A

tuple unpacking/ assignment
x, y = (1, 2)
x=1
y=2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

tuple notation

A

t = ‘a’, ‘b’, ‘c’
OR
t = (‘a’, ‘b’, ‘c’)
t1 = (‘a’,)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

function to create tuple

A

tuple()
tuple(‘word’) = (‘w’, ‘o’, ‘r’, ‘d’)
tuple([list]) = (item1, item2, item3)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

method to create modified tuple with changes by adding new tuple with slice of original tuple

A

tuple replacement
t = (‘a’, ‘b’, ‘c’)
t = (‘A’,) + t[1:] = (‘A’, b’, ‘c’)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

using operators to compare sequential tuple elements. Returns true or false depending on first mismatching pair of values

A

tuple comparison

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

building a LIST of tuples with one or more sort keys (eg. length of word) preceding the elements (eg. word) from the sequence

A

Decorate
(DSU)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

use list method to put list of tuples in order. Compares 1st element in tuple pair, only looks at 2nd element to break ties

A

Sort
list.sort()
(DSU)

17
Q

extract the sorted sequence elements

A

Undecorate
(DSU)

18
Q

method format to sort list in decreasing order

A

list.sort(reverse=True)

19
Q

swap values of two variables in a single statement using tuples
can use with any kind of sequence
form of tuple unpacking

A

a, b = b, a
left side= variables. right side= expressions
ride side evaluated before assigned to left side variables

20
Q

dictionary method that returns a list of tuples (key-value pairs)
way to output contents of dictionary sorted by key

A

.items()

t = dict_name.items()

21
Q

term meaning no particular order

A

hash key order

22
Q

built-in function that takes sequence as parameter and returns same elements in opposite order
needs list() function before it

A

list(reversed())

23
Q

built-in function that takes sequence as parameter and returns same elements in order
does NOT need list() function before it

A

sorted()

24
Q

way to create a list from another list

A

list comprehension

int_strings = [‘42’, ‘65’, ‘12’]
list_of_ints = [int(x) for x in int_strings ]
print(sum(list_of_ints))

25
Q

errors caused when a data structure has the wrong type, size, or composition or the wrong type introduced in the code

A

shape error

26
Q

function that constructs or creates object instances
eg. tuple function constructs tuples

A

constructor function