Skip to content

Instantly share code, notes, and snippets.

@inlinestyle
Last active August 29, 2015 14:14
Show Gist options
  • Save inlinestyle/1a230d0b1a4d77988db7 to your computer and use it in GitHub Desktop.
Save inlinestyle/1a230d0b1a4d77988db7 to your computer and use it in GitHub Desktop.
Lecture outline for Python Lists/Dicts talk

Lists:

  • Making lists with stuff in them

Item Access

  • access just like strings!
  • O-indexed
  • assignment with list[index] syntax, touch on mutability ("this can be changed, strings can't")

Length

  • also just like strings!

Iteration

  • Assume class has seen for/while before, provide examples with lists

Concatenation

  • +

Containment

  • in

Methods

  • .append()
  • .pop()
  • .sort()

Dicts

  • Making dicts with stuff in them
  • Talk about how they aren't ordered

Item Access

  • access looks like lists and strings!, but is a little bit different.
  • assignment is kind of like with lists, but you can add whole items!

Iteration

  • example of iteration over keys
  • introduce .keys() and .values() by way of iteration examples

Containment

  • in

Boundaries and Exceptions

Lists

  • Accessing items out of bounds: What happens? How can we decide whether to try accessing a certain index?
  • len to the rescue!

Dicts

  • Accessing items that aren't present: What happens? How can we decide whether to try accessing a certain index?
  • .get() and in to the rescue!
@inlinestyle
Copy link
Author

It's useful but... a large number of python programmers seem to go years without learning about enumerate

@inlinestyle
Copy link
Author

If we were teaching in ruby I would definitely cover each_with_index, but in python it's a little obscure. We'd also have to talk about tuple unpacking, which might or might not be worth it.

@eriktaubeneck
Copy link

little late, but FWIW I agree with @inlinestyle. I rarely use enumerate and typically see it enforcing C or Java patterns that are ideally avoided in Python.

this outline looks great. good work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment