1 of 13

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!

slido.com

#2348882

2 of 13

Announcements

  • Yesterday’s Section Check-in 1 due tonight at 11:59 PM!
  • Programming Practice 1 released yesterday and due next Thursday on Gradescope!
  • Homework 1: Processing released today and due next Friday
  • As usual, Lesson Review 1.3 due tonight.

slido.com

#2348882

3 of 13

Grading Clarifications

  • Make sure to answer all questions in the section check-in!
    • The last question “section code” is not referring to your section name or code you wrote during section.
  • Lesson reviews are graded on accuracy, however the free response type questions are graded more leniently.
  • Submit your .py files for programming practices directly to Gradescope.
    • Homework assignment specifications will specify which files are needed for submission.

slido.com

#2348882

4 of 13

List Comprehensions

squares = [

for i in range(1, 11)

if i % 2 == 0

squares.append(i ** 2)

i ** 2

slido.com

#2348882

5 of 13

List Comprehensions

squares.append(i ** 2)

squares = [

]

i ** 2

for i in range(1, 11)

if i % 2 == 0

slido.com

#2348882

6 of 13

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

slido.com

#2348882

7 of 13

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

slido.com

#2348882

8 of 13

Tuples

  • A tuple is a lot like a list, but it is immutable!

t = (1, "hello", 3.4)

print(t) # (1, 'hello', 3.4)

print(t[0]) # 1

t[1] = 'goodbye' # Error!

slido.com

#2348882

9 of 13

Unpacking Tuples

  • We can “unpack” tuples to get their contents
  • The number of variables MUST match the number of tuple elements!

t = (1, "hello", 3.4)

# Good!

a, b, c = t

# Not good!

a, b = t

a, b, c, d = t

slido.com

#2348882

10 of 13

Set

  • Data structure highly optimized for membership queuries
    • “if x in set” is very fast!
  • Acts a lot like a list, BUT
    • Does not allow indexing operations
    • Does not allow duplicates

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

slido.com

#2348882

11 of 13

Dictionary

  • Python has a data structure called a dictionary that allows us to use arbitrary data as keys
    • Keys are unique, but values need not be!
    • Lesson 6 will show some more advanced usages of the dictionary

d = {}

d['a'] = 1

d['b'] = 2

print(d) # {'a': 1, 'b': 2}

slido.com

#2348882

12 of 13

Type Annotations

  • Sometimes our data structures will have many different data types in it!
  • Careful about how you use pipes ( | ) and commas ( , )
    • list[str | int] means a list of strings, ints, or both
    • list[str, int] means a list of strings AND ints
    • This also applies to parameters and returns!

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]:

slido.com

#2348882

13 of 13

Assert Statements and Testing

  • Use assert statements to test your code more reliably

  • You’ll use these for Homework 1, and future Homeworks!
  • Can be used for all return types (ints, floats, strings, lists, None, etc.)
  • For floats, need to use math.isclose()

  • Write meaningful tests!
    • Tests should be unique and informative
    • Test for edge cases and unexpected behavior

slido.com

#2348882

assert myfunc(...) == <expected_output>

assert math.isclose(myfunc(...), 2.333)