Module 5: Sorting and Dictionaries Flashcards
________ works if we have a list. it will mutate the list to make it sorted. Can put a ______ or ______ inside the brackets.
list.sort()
key
reverse
_________ 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.
sorted(listname,key=/reverse=)
______ 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.
reverse, false, true
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.
key
a ________ means that items that are equal stay in the same order they are already in
stable sort
A dictionary represents a _______ from keys to values.
mapping
{ } represent ________, dict[ ] = value represents ________, { : } represent _______,
use _______ brackets for dict type
empty dictionary, add items in dictionary, key-value pair between key and colon
square
unlike lists dictionaries have no direct way to ________
ask for values by index.
using the len function on a dictionary returns ________
number of key-value pairs
using the in operator in dictionaries tells you whether something __________ in true or false
appears as a key
a ________ is a term for a collection for counters.
histogram
to describe a dictionary write _________.
dict[KEYTYPE, VALUETYPE]
in dictionaries the order of the keys __________.
does not matter
Sorted does not _________ a list, it _________.
mutate
returns a new list
Sorted takes any iterable and turns it into a _______.
list
For upper or lowercase letters sorted returns ______ first.
uppercase
list.sort works on _________, not ________.
list
anything else
a ________ is a parameter that is a bool.
flag
________ is a function used to determine how many times a letter appears in a string.
str.count()
*type character inside brackets
use a for loop to go through _______.
keys
To add a new item to a dictionary, assign a ________ using a ________ as index.
new value
new key
To change an item, assign a ________ using a ________ as index.
new value
existing key
To remove a key:value pair, use _________ using ________.
dict.pop()
existing key
Impossible to have same ______, can have many same _______.
key
values