CSE 163
Data Structures
Arpan Kapoor�Summer 2026��💭Icebreaker (discuss with neighbors):
What’s one fun thing you’re looking forward to this weekend?
Add to our Slido!
#2348882
Announcements
#2348882
Grading Clarifications
#2348882
List Comprehensions
squares = [
for i in range(1, 11)
if i % 2 == 0
squares.append(i ** 2)
i ** 2
#2348882
List Comprehensions
squares.append(i ** 2)
squares = [
]
i ** 2
for i in range(1, 11)
if i % 2 == 0
#2348882
List Comprehensions
squares.append(i ** 2)
squares = [
]
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
#2348882
List Comprehensions
squares.append(i ** 2)
squares = [
]
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
#2348882
Tuples
t = (1, "hello", 3.4)
print(t) # (1, 'hello', 3.4)
print(t[0]) # 1
t[1] = 'goodbye' # Error!
#2348882
Unpacking Tuples
t = (1, "hello", 3.4)
# Good!
a, b, c = t
# Not good!
a, b = t
a, b, c, d = t
#2348882
Set
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 |
#2348882
Dictionary
d = {}
d['a'] = 1
d['b'] = 2
print(d) # {'a': 1, 'b': 2}
#2348882
Type Annotations
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]:
#2348882
Assert Statements and Testing
#2348882
assert myfunc(...) == <expected_output>
assert math.isclose(myfunc(...), 2.333)