Level 73 Level 75
Level 74

[Quiz] Dictionary

95 words 0 ignored

Ready to learn       Ready to review

Ignore words

Check the boxes below to ignore/unignore words, then click save at the bottom. Ignored words will never appear in any learning session.

All None

A mapping from a set of keys to their corresponding values.
key-value pair
The representation of the mapping from a key to a value.
One of the basic units of data, like a number or string, that a program manipulates
A way of performing a computation.
hash function
A function used by a hashtable to compute the location for a key.
An object is hashable if it is immutable (ints, floats, tuples, strings, etc) or user-defined classes that define a __hash__ method.
A dictionary operation that takes a key and finds the corresponding value.
reverse lookup
A dictionary operation that takes a value and finds one or more keys that map to
A list (or other sequence) with a single element.
call graph
A diagram that shows every frame created during the execution of a program, with an
A set of counters.
A computed value stored to avoid unnecessary future computation.
A boolean variable used to indicate whether a condition is true.
A statement like global that tells the interpreter something about a variable
global variable
A variable defined outside a function. Global variables can be accessed from any
Python shell prompt
Return absolute Value of a number
Extra information which the computer uses to perform commands
Parser for Command-Line Options, arguments and sub-commands
Used while debugging to check for conditions that ought to apply
Giving a value to a variable
one or more lines of code grouped together with the same minimum amount of indentation
Used to exit a for loop or a while loop
Template for creating user-defined Objects
A program that converts an entire program into machine code before the program is executed.
Terminate the smallest enclosing loop and immediately continue with the next iteration of the loop.
conditional statement
if x == y
The process of finding and removing any of the three kinds of programming errors.
Defines a function or method
beatles = ["John","Paul","George","Ringo","me"]
str.index(sub[, start[, end]])
takes a list and modifies it so that it is in numerical or alphabetical order
allows you to remove an item from a dictionary, usually an entire entry
allows you to remove an item from a dictionary, usually part of an entry
used when you need to find where an item is in a list
used when you need to add and item into a list, not just at add it to the end
used to add items to the end of a list
By key (as opposed to by index)
How are dictionary items accessed (as opposed to list items)
Similarities between lists and dictionaries
Variable-length (can be added to and subtracted from), Heterogenous (can contain any object type), Nestable (can contain any number of lists or other dictionaries as values, both store values by reference. Also a value…
Major differences between lists and dictionaries
Dictionaries are not ordered, and don't support the same sequence operations that work on strings and lists.
Syntax of dictionary declarations
Series of key:value pairings, separated by commas, enclosed in braces --> {a:2, 'age':3, 'peter':[1, 2, 3]}
Removes all items from D
Returns shallow copy of D
Returns new dict with keys from S and values equal to v, which defaults to None
Returns D[k] if k in D, else d, which defaults to none
Returns True if D has a key k, else False
List of D's key:value pairs, as 2-tuples
an iterator over the key:value items of D
an iterator over the keys of D
an iterator over the values of D
Returns list of D's keys
Removes specified key and returns the corresponding value. If key is not found, d is returns if given, otherwise KeyError is raised
Removes and returns some key:value pair as a 2-tuple, raises KeyError if D is empty
D.setdefault(key, default)
Fetch by key, if absent set default
Merges the key:value pairings of two dictionaries, blindly overwriting value of the same key if there's a clash
Returns list of D's values
Returns a set-like object providing a view on D's items
Returns a set-like object providing as view on D's keys
Returns an object providing a view on D's values
dict(name='Bob', age=40)
A dictionary with items 'name':'Bob' and 'age':40
dict.fromkeys(['a', 'b'], 0)
A dictionary with items 'a':0 and 'b':0
dict(zip(['a', 'b', 'c'], [1, 2, 3]))
A dictionary with items 'a':1, 'b':2, 'c':3, but not necessarily in that order
A dictionary, D, with items 1:1, 2:4, 3:9, 4:16
D = {x: x**2 for x in [1, 2, 3, 4]}
examples of immutable data
6, True, 'happy' - The literal cannot be changed
Dictionary rules
key must be immutable and unique.
(pronounced TUH-pul or TOO-pul) A built-in Python datatype, which is an immutable ordered sequence of values. Note that only the sequence itself is immutable. If it contains a mutable value such as a dictionary, …
Dictionary example
d = { 'joe' : 18, 'lisa': 20 , 'jerry' : 18 }
How to access all of the keys? values?
Using .pop
How do you remove things from a dictionary?
comma separated values files
What does csv stand for?
How to access items within a dictionary
Number of key value pairs
What will then len function return from a dictionary?
k in d or k not in d
Will check to see if a value is within a dictionary
What will d.get(key) return?
Will find value at that key
Difference between d[key] and d.get(key)
d[key] returns an error if not found
value that means nothing there null in other languages
What does d.pop(key) return?
Removes the key value pair from the dictionary.
An object with fixed value. Immutable objects include numbers, strings and tuples. Such an object cannot be altered. A new object has to be created if a different value has to be stored. They …
f(a, b=6)
Setting default cases within function
def functionName (a, b, * args)
How to make function that can accept as many parameters as needed?
def f(a,b,*lucky, c=5):
keyword only/positional parameter category example
Variable length keywords
def f(1,2,3,c=6,x=12,y=13,joe=7)
Variable length example
def g(*args, **kwargs):
Key and value.
An element in a dictionary has two parts. What are they called?
The string 'start' is the key, and the integer 1472 is the value.
Suppose 'start' : 1472 is an element in a dictionary. What is the key? What is the value?
employee['id'] = 54321
It stores the key-value pair 'id' : 54321 in the employee dictionary.
How can you determine whether a key-value pair exists in a dictionary?
You can use the in operator to test for a specific key.
del inventory[654]
It deletes the element that has the key 654.
What is the difference between the dictionary methods pop and popitem?
The pop method accepts a key as an argument, returns the value that is associated with that key, and removes that key-value pair from the dictionary. The popitem method returns a randomly selected key-value p…
any character except newline
What does the keys method return?
It returns all the keys in a dictionary as a sequence of tuples.
What does the values method return?
It returns all the values in the dictionary as a sequence of tuples