Data Structures Assessment Test Flashcards

1
Q

Describe the types of numbers used in python.

A

Floating points (float) ∈ R,

Integers (int) ∈ Z.

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

Describe what are strings.

A

Ordered sequence of characters.

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

Describe what are lists.

A

Ordered sequence of objects (mutable).

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

Describe what are tuples.

A

Ordered sequence of objects (immutable).

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

Describe what are dictionaries.

A

Key-value pairing that is unordered.

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

What would you use to find a number’s square root?

A

x**0.5

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

Reverse the string ‘hello’ using slicing.

A

s[: :-1].

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

Build this list [0,0,0] two serarate ways.

A

Method 1: [0]*3

Method 2: list2 = [0,0,0], list2.

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

Sort the list below:

list4 = [5,3,4,6,1].

A

sorted(list4)

or

list4.sort()

list4.

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

Grab hello from the dictionary,

d = {‘k1’ : [{‘nest_key’ : [‘this is deep’, [‘hello’] ] } ] }.

A

d[‘k1’][0][‘nest_key’][1][0].

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

Grab ‘hello’ from the dictionary below:

d = {‘k1’:[1,2,{‘k2’:[‘this is tricky’,{‘tough’:[1,2,[‘hello’]]}]}]}.

A

d[‘k1’][2][‘k2’][1][‘tough’][2][0].

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

Can you sort a dictionary? Why or why not?

A

No, because normal dictionaries are mappings not a sequence.

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

What is the major difference between tuples and lists?

A

List are mutable, tuples are immutable.

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

How do you create a tuple t with items of 1,2,3?

A

t = (1,2,3).

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

What is unique about a set?

A

They don’t allow for duplicate items.

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

Use a set ot find unique values of the list below:

list5 = [1,2,2,33,4,4,,11,22,3,3,2].

A

set(list5).

17
Q

In python, is this statement true/false?

3.0 == 3.

A

True.

No approximations needed in python.

18
Q

In python, is this statement true/false?

4**0.5 != 2.

A

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.

19
Q

Why doesn’t 0.2 + 0.1 - 0.3 == 0.0 in python?

A

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.