Data Structures Assessment Test Flashcards
Describe the types of numbers used in python.
Floating points (float) ∈ R,
Integers (int) ∈ Z.
Describe what are strings.
Ordered sequence of characters.
Describe what are lists.
Ordered sequence of objects (mutable).
Describe what are tuples.
Ordered sequence of objects (immutable).
Describe what are dictionaries.
Key-value pairing that is unordered.
What would you use to find a number’s square root?
x**0.5
Reverse the string ‘hello’ using slicing.
s[: :-1].
Build this list [0,0,0] two serarate ways.
Method 1: [0]*3
Method 2: list2 = [0,0,0], list2.
Sort the list below:
list4 = [5,3,4,6,1].
sorted(list4)
or
list4.sort()
list4.
Grab hello from the dictionary,
d = {‘k1’ : [{‘nest_key’ : [‘this is deep’, [‘hello’] ] } ] }.
d[‘k1’][0][‘nest_key’][1][0].
Grab ‘hello’ from the dictionary below:
d = {‘k1’:[1,2,{‘k2’:[‘this is tricky’,{‘tough’:[1,2,[‘hello’]]}]}]}.
d[‘k1’][2][‘k2’][1][‘tough’][2][0].
Can you sort a dictionary? Why or why not?
No, because normal dictionaries are mappings not a sequence.
What is the major difference between tuples and lists?
List are mutable, tuples are immutable.
How do you create a tuple t with items of 1,2,3?
t = (1,2,3).
What is unique about a set?
They don’t allow for duplicate items.