This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Folders and files Name Name Last commit message
Last commit date
parent directory
View all files
Lesson 6 - Dealind with Sequences of Objects
list("string") => ['s', 't', 'r', ...]
Each item in a list is called an element
Can be accessed by referring to its index
Slicing
[start, end]
Does not include the element at index end
Nested lists
Lists containing another list
Mutable - can be altered
del list[1]
removes the element at index 1
Overloaded operators
Concatenation +
Repetition *
Note to self, strings are character arrays
Membership
in
checks if element is in the list
Iterate over a collection of objects
continue
Jumps back to the beginning of the loop
range(start, end)
Ending number not included in the "range"
VS while
Use for when iterating over a fixed collection
Don't modify the list while iterating
while
loops give more control
Detached head
unreachable without commit hash
Tuples are immutable
Can't be changed
Can't add elements, remove elements, nor change elements
Single element tuple (1,)
Overloaded operators
Test driven development
Write test cases before writing the function
Convention
Start function names with test_
Focus on edge cases
Think of all possible cases that could go wrong
Unit testing
Testing the correctness of a single unit of the code
Debug mode
No spaces before opening bracker
No spaces immediately inside bracket
Spaces in slicing operations
Trailing commas
Useful when list is expected to be extended
No space between trailing comma and closing parenthesis
Aligning brackets
You can’t perform that action at this time.