Presentation is loading. Please wait.

Presentation is loading. Please wait.

Nate Brunelle Today: Dictionaries

Similar presentations


Presentation on theme: "Nate Brunelle Today: Dictionaries"— Presentation transcript:

1 Nate Brunelle Today: Dictionaries
CS1110 Nate Brunelle Today: Dictionaries

2 Questions?

3 Tips for fixing bugs in code
Know what your code should do Read error messages Believe the error message Print every variable Binary search Test more Look for “code coverage”

4 Binary search Start: a line you know is before the bug
End: a line you know is after the bug Middle: the line halfway between start and end Check whether Middle has the bug. If so, then Middle is the new End. Otherwise if Middle has no bug, then Middle is the new Start. You just ruled out half of the remaining lines of code as the bad ones! Keep going until you have only 1 line of code left. That one has the bug.

5 Test Cases Try winning: fun, f, u, n Capital: FUN, f, u ,n 1234, 1
Fun, fn, Fun, x, x, x, x, x, x F_n, n, _

6 Collections Order doesn’t matter, No Repetition
Order Matters, Repetition ok Examples: String List Tuple Range Counting starts at 0 collection[index] gives a specific value in the collection Order doesn’t matter, No Repetition Examples: Set Dict Map Table

7 Set Things are unordered Cannot have repetition

8 Dict A set of key:value mappings d = { } d[‘name’] = 1 d[‘name’]

9 Dict Somewhat like variables, somewhat like a list

10 Dict is like variables Gives names to values Create using =
Reassign using = Easy to go from name to a value Very hard to go from value to name

11 Dict is like a list Index to access members Index must be an int
Key to access members Key can be any immutable type No rules for values of keys To add in a new thing: d[key] = … Index to access members Index must be an int Indexes cannot be skipped To add in a new thing: lst.append(…)


Download ppt "Nate Brunelle Today: Dictionaries"

Similar presentations


Ads by Google