Chapter 10: Tuples Flashcards
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.
comparable
A collection of related values, often organized in lists, dictionaries, tuples, etc.
data structure
A pattern that involves building a list of tuples, sorting, and extracting part of the result.
DSU
The operation of assembling a variable-length argument tuple.
gather/
tuple packing
A type that has a hash function. Immutable types like integers, floats, and strings are this; mutable types like lists and dictionaries are not.
hashable
The operation of treating a sequence as a list of arguments.
scatter
A summary of the type, size, and composition of a data structure.
shape
(of a data structure)
A list (or other sequence) with a single element.
singleton
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)
tuple
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
tuple unpacking/ assignment
x, y = (1, 2)
x=1
y=2
tuple notation
t = ‘a’, ‘b’, ‘c’
OR
t = (‘a’, ‘b’, ‘c’)
t1 = (‘a’,)
function to create tuple
tuple()
tuple(‘word’) = (‘w’, ‘o’, ‘r’, ‘d’)
tuple([list]) = (item1, item2, item3)
method to create modified tuple with changes by adding new tuple with slice of original tuple
tuple replacement
t = (‘a’, ‘b’, ‘c’)
t = (‘A’,) + t[1:] = (‘A’, b’, ‘c’)
using operators to compare sequential tuple elements. Returns true or false depending on first mismatching pair of values
tuple comparison
building a LIST of tuples with one or more sort keys (eg. length of word) preceding the elements (eg. word) from the sequence
Decorate
(DSU)