CSE 163
Tuples, Sets, and Dictionaries!
Oh My!�
Suh Young Choi�
🎶 Listening to: C418
💬 Before Class: Do you have a favorite extinct creature/plant? Why not?
This Time
Last Time
2
Project Data Exploration
Find 2 datasets that you may want to explore for the final project and answer some questions about them.
This is not a commitment, just an exploration!
Project Data Exploration due on Gradescope at 11:59pm, Monday 7/7
Submit a PDF! (Other file types do not load in Gradescope, so we cannot grade them.)
3
Recap
Learned about 4 data structures so far!
4
List Comprehensions
squares = [
5
]
for i in range(1, 11)
if i % 2 == 0
:
:
squares.append(i ** 2)
i ** 2
List Comprehensions
squares = [
6
squares.append(i ** 2)
]
i ** 2
for i in range(1, 11)
if i % 2 == 0
List Comprehensions
squares = [
7
squares.append(i ** 2)
]
i ** 2
for i in range(1, 11)
if i % 2 == 0
4) Put it all in a list
3) Expression with � loop variable
1) What are you looping � over?
2) [Optional] Skip if this �is false
List Comprehensions
squares = [
8
squares.append(i ** 2)
]
i ** 2
for i in range(1, 11)
if i % 2 == 0
squares = [
]
for i in range(1, 11)
if i % 2 == 0
:
:
squares.append(i ** 2)
i ** 2
expression 🡪 iteration 🡪 condition
iteration
condition
expression
Tuples
9
t = (1, "hello", 3.4)
print(t) # (1, 'hello', 3.4)
print(t[0]) # 1
t[1] = 'goodbye' # Error!
Unpacking�Unpacking
10
t = (1, "hello", 3.4)
# Good!
a, b, c = t
# Not good!
a, b = t
a, b, c, d = t
Set
Set Methods
11
set() | Makes an empty set |
s.add(x) | Adds x to s |
s.remove(x) | Removes x from s |
s.clear() | Removes all values from s |
Dictionary
12
d = {}
d['a'] = 1
d['b'] = 2
print(d) # {'a': 1, 'b': 2}
That which we call a data structure…
13
strings: list[str] = [‘by’, ‘any’, ‘other’, ‘name’]
numbers: dict[str, float] = {“Act 2”: 2.24}
def mystery(a: bool | int, b: int) -> set[str, float]:
Group Work:
Best Practices
When you first working with this group:
Tips:
14
Before Next Time
Next Time
15