Module 5: Sorting and Dictionaries Flashcards

1
Q

________ works if we have a list. it will mutate the list to make it sorted. Can put a ______ or ______ inside the brackets.

A

list.sort()
key
reverse

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

_________ is used if we have any kind of iterable that can be converted to a list. returns a new list containing all the values in order.

A

sorted(listname,key=/reverse=)

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

______ is a flag meaning its is a bool. It uses the default value _______.If a flag is set it uses value ______ and result is in descending order.

A

reverse, false, true

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

a _____ function is an optional parameter that is a callable and is used to transform each item then put the original values in order so the transformed values are sorted.

A

key

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

a ________ means that items that are equal stay in the same order they are already in

A

stable sort

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

A dictionary represents a _______ from keys to values.

A

mapping

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

{ } represent ________, dict[ ] = value represents ________, { : } represent _______,
use _______ brackets for dict type

A

empty dictionary, add items in dictionary, key-value pair between key and colon
square

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

unlike lists dictionaries have no direct way to ________

A

ask for values by index.

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

using the len function on a dictionary returns ________

A

number of key-value pairs

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

using the in operator in dictionaries tells you whether something __________ in true or false

A

appears as a key

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

a ________ is a term for a collection for counters.

A

histogram

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

to describe a dictionary write _________.

A

dict[KEYTYPE, VALUETYPE]

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

in dictionaries the order of the keys __________.

A

does not matter

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

Sorted does not _________ a list, it _________.

A

mutate
returns a new list

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

Sorted takes any iterable and turns it into a _______.

A

list

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

For upper or lowercase letters sorted returns ______ first.

A

uppercase

17
Q

list.sort works on _________, not ________.

A

list
anything else

18
Q

a ________ is a parameter that is a bool.

A

flag

19
Q

________ is a function used to determine how many times a letter appears in a string.

A

str.count()
*type character inside brackets

20
Q

use a for loop to go through _______.

A

keys

21
Q

To add a new item to a dictionary, assign a ________ using a ________ as index.

A

new value
new key

22
Q

To change an item, assign a ________ using a ________ as index.

A

new value
existing key

23
Q

To remove a key:value pair, use _________ using ________.

A

dict.pop()
existing key

24
Q

Impossible to have same ______, can have many same _______.

A

key
values