Chapter 9 Key Terms Flashcards

1
Q

Dictionary

A

Object that stores a collection of data.

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

key

A

Identifier for a value. They are used to access, modify, or add values.

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

value

A

The data associated with or within a key, are typically numbers, lists, strings, and can even be other dictionaries.

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

Syntax for Creating a Dictionary

A

dictionary =
{key1:val1, key2:val2}

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

Syntax for Retrieving a Value from a Dictionary

A

dictionary[key]

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

in

A

Is used to check if a key exists in a dictionary.

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

not in

A

Is used to check if a key does not exist in a dictionary.

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

Syntax for Adding Elements in a Dictionary

A

dictionary[key] = value

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

del

A

Is used to remove an element.

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

len

A

Is used to obtain a number of elements.

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

Data Types in a Dictionary

A

Data types such as integers, strings, lists, other dictionaries, etc.

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

Syntax for Creating an Empty Dictionary

A

empty_dict = {}

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

clear

A

Is used to remove all items from a dictionary.

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

get

A

Gets a value associated with a specified key.

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

items

A

Returns all the dictionary keys and associated values.

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

keys

A

Returns all the dictionary keys as a sequence.

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

pop

A

Returns value associated with the specified key and removes that key-value pair from the dictionary.

18
Q

popitem

A

Removes and returns a random key-value pair from the dictionary.

19
Q

values

A

Returns a list of values in the dictionary.

20
Q

Dictionary Comprehension

A

An expression that reads a sequence of input elements and uses those input elements to produce a dictionary.

21
Q

if clause with Dictionary Comprehension

A

Used to select only certain elements of the input sequence.

22
Q

Set

A

An object that stores a collection of data in the same way as a mathematical set.

23
Q

Syntax for Creating a Set

A

my_set = {1,2,3}

24
Q

len and Set

A

len is used to get the number of elements in a set.

25
Q

Syntax for Adding and Removing Elements in a Set

A

my_set.add ()
my_set.remove ()

26
Q

in, not in, and Sets

A

in and not in are used to check if an element is present within a set.

27
Q

union

A

Is used to combine two sets; and contains elements of both sets.

28
Q

|

A

An operator is used to help find the union of two sets.

29
Q

intersection

A

A set that contains only the elements in both sets.

30
Q

difference

A

A set that contains the elements that appear in the first set but do not appear in the second set

31
Q

symmetric_difference

A

A set that contains elements not shared by the two sets.

32
Q

issubset

A

Checks if one set is a subset of another.

33
Q

issuperset

A

Checks if one set is a superset of another.

34
Q

set2 <= set1

A

Checking if set2 is a subset of set1.

35
Q

set1 >= set2

A

Checking if set1 is a superset of set2.

36
Q

Set Comprehension

A

A concise expression that creates a new set by iterating over the elements of a sequence.

37
Q

Serializing Objects

A

Convert the object to a stream of bytes that can easily be stored in a file.

38
Q

open

A

Is used to open files for reading and writing.

39
Q

dump

A

Is used to serialize an object and save it to a file using the pickle module.

40
Q

close

A

Is used to close a file.

41
Q

load

A

Is used to deserialize an object from a file using the pickle module.