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
Syntax for Adding and Removing Elements in a Set
my_set.add () my_set.remove ()
26
in, not in, and Sets
in and not in are used to check if an element is present within a set.
27
union
Is used to combine two sets; and contains elements of both sets.
28
|
An operator is used to help find the union of two sets.
29
intersection
A set that contains only the elements in both sets.
30
difference
A set that contains the elements that appear in the first set but do not appear in the second set
31
symmetric_difference
A set that contains elements not shared by the two sets.
32
issubset
Checks if one set is a subset of another.
33
issuperset
Checks if one set is a superset of another.
34
set2 <= set1
Checking if set2 is a subset of set1.
35
set1 >= set2
Checking if set1 is a superset of set2.
36
Set Comprehension
A concise expression that creates a new set by iterating over the elements of a sequence.
37
Serializing Objects
Convert the object to a stream of bytes that can easily be stored in a file.
38
open
Is used to open files for reading and writing.
39
dump
Is used to serialize an object and save it to a file using the pickle module.
40
close
Is used to close a file.
41
load
Is used to deserialize an object from a file using the pickle module.