Exam Revision] Flashcards

(28 cards)

1
Q

What is a Hash function?

A

A function that maps a key to a value.

An example of this is a dictionary

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

True or false?

The keys of dictionaries must be immutable

A

True

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

True or false?

A valid dictionary key is (1, 2, 3)

A

True because tuples are immutable

Note that lists are not immutable

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

In the ordering of string characters, do capital letters or lowercase letters come first?

A

Capital letters come first.

Meaning "A" < "a" is true

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

What does len(“hello world”) return?

A

11

Note it does not start from 0

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

Is string splicing right exlusive or left exclusive?

A

Right exlcusive

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

A.

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

D. 6 This is because the x == a is seperate from the rest (or "c" or "e" or "g"). And so at x = a, the first condition is fufilled (if x == a:), and for the rest of the letters, it will basically run if "c": which is always true and so the if statement will run for all letters

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

C.

You can add lists

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

A

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

What is the difference between extend and append?

A

extend adds multiple elements of an iterable element (concerting them to singular elements).
append adds only one element.

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

C.

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

D. Error You cannot change individual characters in a string

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

C. NameError

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

C. None “*IN PLACE*” means it replaces the list, not creating a new one so using it actually returns nothing

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

B. ValueError

Because it is the correct type, being a string but not correct value

17
Q
A

D. <class ‘NoneType’>

18
Q

For the instantiations at line 35-38, define each f and g functions as mathmatical representations. Like a.f(x)= 2x+5 or a.g(x)= 3x-7

19
Q
A

A. 5.

Each \t counts as 1 character

20
Q
A

D. 3

Note and takes precedence over or

23
Q
A

D. None of the above

It will print 6

24
Q
A

foo always raises an error. Dictionaries cannot have mutable keys (lists)

25
B. ValueError
26
**D. foo returns True only when every element of xs is a value of ys.**
27
28