Chapter 8: Dictionaries And Sets Flashcards

1
Q

In a dictionary, you specify a unique ____ to associate with each _____

A

Key,value

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

How to create a empty dictionary

A

Empty_dic = {}

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

How to create a dictionary (not empty)

A

Acme_customer = {‘first’:’Wile’, ‘middle’: ‘E’, ‘last’: ‘Coyote’}

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

You can also use the ____ function to convert two-value sequences into a dictionary

A

Dict()
- a list of two items lists
A list of two-item tuple
- a list of two character strings
A tuple of two-character strings tos = (‘ab,’cd’,ef’)

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

To add an item, refer to the item by its key and assign a ______. If the key is already present, the existing value is______ by the new one, If it is new, it is ____.

A

Value,replaced,added

Pythons[‘Gilliam’] = ‘Gerry’

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

How to get a value given a key

A

Get()

Ex:
Some_pythons.get(‘John’)

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

This function also you get get all keys in dictionary

A

Keys()

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

Allows you yo get all values in dictionary

A

Values()

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

When you want to get all key-value pairs from dictionary use ____

A

Items()

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

When using items(), each key and value is returned as a ___

A

Tuple

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

Get the length of dictionary

A

Len()

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

Combine dictionaries using _____

A

{a,b}
A = first dictionary
B = second dictionary

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

You can use the ____ function to copy the keys and values of one dictionary into another

A

Update()

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

Delete an item by key with ___

A

Del
Del pythons[‘Marx’]

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

If you give ___ a key and it exists in dictionary, it returns the matching value and delete the key value pair. If it does not exist, it raises an exception

A

Pop()

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

How to delete all items in dictionary

17
Q

The ____ function copy’s key and values from one dictionary to another

18
Q

Iterate over keys in dictionary

A

For card in accusation \or for card in accusation.keys()

19
Q

Iterate over values rather than keys

A

For value in accusation.values()

20
Q

To return both key and tuple using for loop

A

For item in accusation.items()

21
Q

A set is like a dictionary with its _____ thrown away leaving only ____

A

Values, keys

22
Q

The ___/____ set is a set with zero items

A

Null,empty

23
Q

To create a set, you use the ____ function to enclose one or more comma separated value in curly brackets

A

Even_numbers = {0,2,4,6}

24
Q

You can create a set from a list, string, tuple, or dictionary using _____

25
Q

Throw another item into a set with the set ____ method

26
Q

You can delete an item from a set using the function _____

27
Q

You can iterate over the items in a set using ____ and _____

28
Q

You can test for a value with ____

A

In

Ex:
If ‘vodka’ in contents:

29
Q

Set intersection operator

30
Q

Exams of combinations and operators

A

Ex:
For name,contents in drinks.item()
If ‘vodka’ in content and not content & {‘vermouth’,’cream’}
Print(name)

31
Q

Intersection function

A

Intersenction()

32
Q

In this example, get the union by using __ or the set ____ function

A

|, union()

33
Q

The exclusive or uses ___ or ______ function

A

^, symmetric_difference()

34
Q

You can check whether on set is a subset of another by using ___ or ____

A

<=, issubset()

35
Q

A superset is opposite of subset and uses ____ or _____

A

> =, issuperset()

36
Q

If you want to create a set that can’t be changed, call the ____ function with any iterable argument

A

Frozenset()

Frozenset([3,2,1])