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.
Use a set ot find unique values of the list below:
list5 = [1,2,2,33,4,4,,11,22,3,3,2].
set(list5).
In python, is this statement true/false?
3.0 == 3.
True.
No approximations needed in python.
In python, is this statement true/false?
4**0.5 != 2.
False.
0.5 is a binary fraction. No approximation is needed which means no floating point errors are made in python so 4**0.5 ==2.
Why doesn’t 0.2 + 0.1 - 0.3 == 0.0 in python?
Python uses binary fractions to estimate all fractions. So every fraction that cannot be accurately represented by a binary fraction (1/2x) will be approximated and will carry approximation errors.
In python,
0.2 + 0.1 - 0.3 == 5.551115123125783e-17.