Back to marketplace

Tuples & Dictionaries (UCSD - Wk 2)

No description yet. This curated deck is ready for daily study.

Total cards: 24•Content version: v4•Public deck•Updated: 8/1/2026

Card preview (24)

#1
Front (Question)

how do you pronounce tuple

Back (Answer)

too pel

#2
Front (Question)

What is the difference between a tuple and a list?

Back (Answer)

A tuple is immutable (you can’t change any of the values)

#3
Front (Question)

What’s the difference in how you instantiate a tuple and a list?

Back (Answer)

list = [x, y]; tuple = (x, y); can also instantiate a tuple with a list with func: tupleVar = tuple(list)

#4
Front (Question)

Why is it important that it’s immutable for parallel computing?

Back (Answer)

Don’t need to account for multiple threads / people using diff data

#5
Front (Question)

Why is the immumtability important for using tuples with dictionaries?

Back (Answer)

Tuples can be used as keys in dict. since values don’t change, can org on initial value

#6
Front (Question)

What is the python equivalent of a map?

Back (Answer)

Dictionary

#7
Front (Question)

How can we think about the structure of a dictionary?

Back (Answer)

It’s like an index: Key Value Pairs, where Key is immutable (value or tuple)

#8
Front (Question)

What kinds of objects can you store in the value of a dictionary?

Back (Answer)

Any. ints, lists, even other dictionaries

#9
Front (Question)

how do you initialize a dictionary?

Back (Answer)

dict = {key1:value1, key2, value2}

#10
Front (Question)

how do you initialize a dict with a tuple as a key

Back (Answer)

dict = {(key1A, key1B): value1, … }

#11
Front (Question)

lookup value for key1 in dict

Back (Answer)

dict[ key1 ]

#12
Front (Question)

How do you add to a dictionary

Back (Answer)

create a new key / value pair. If key already in use, over-writes value

#13
Front (Question)

is there a fixed order for dictionaries?

Back (Answer)

no. (one of the reasons they’re fast to lookup)

#14
Front (Question)

What happens if you try to retrieve a value for a dict where the key does not exist?

Back (Answer)

get a run-time error

#15
Front (Question)

What’s a safer way to retrieve an element from a dictionary if you’re not sure if the key exists

Back (Answer)

x = dict.get(key); Returns None if key non-existent

#16
Front (Question)

Test to see if a key is in a dictionary

Back (Answer)

key1 in dict; returns bool

#17
Front (Question)

how to retrieve and delete value with key1 in dict

Back (Answer)

dict.pop(key1)

#18
Front (Question)

how to just delete value with key from dict

Back (Answer)

del dict[key1]

#19
Front (Question)

iterate over keys in a dictionary

Back (Answer)

for i in dict: print(i)

#20
Front (Question)

iterate over key values in a dictionary

Back (Answer)

for key, value in dict.items(): print(key, “:”, value)

#21
Front (Question)

can you change a dict while iterating through it?

Back (Answer)

no.

#22
Front (Question)

how do you remove a set of items from a dict with iteration?

Back (Answer)

iterate through appending keys to remove to a new list, then iterate through the list, popping items from orig dict

#23
Front (Question)

how to build a list with squares from 1 to 10 (eg of “comprehension”)

Back (Answer)

list = [i**2 for i in range (1,11)] > can use an iteration and values here

#24
Front (Question)

How to create a list with random numbers (after import random package)

Back (Answer)

list = [random.randint(0,5) for i in range (x,y)]