I haven't yet found any aspects to be extremely challenging because I have had some minimal experience in coding in other languages. I do need to be careful though, because after all, some things like linked lists are still new concepts to me. The most challenging concept will probably be efficiency and Big-O in the later half of the course -- I was never good at it.
And for this week (as a summary of this week's lecture and Friday's class. I have not decided on a set schedule to post yet, though I probably should. I was hoping for bi-weekly):
Stacks:
- NOT built into Python
- Last In First Out (LIFO?)
- Good for balancing parenthesis/delimiters
- left in (, [, { //opening: add to stack
- right out ), ], } //closing: match with most recent, remove from stack
- balanced if out = last in
- concatenation of balanced = balanced
Queue:
- First In First Out (FIFO)
- Coffee Line/Ticket Line
Linked Lists:
- Separate bits of data
- Easier to grab in storage
- Value + "Pointer" // 2 parts
- Concept can be viewed in two ways
- Quite literally like the format of its declaration:
LinkedListNode( value1, LinkedListNode( value2, LinkedList( value3, ...)))
A box inside a box inside a box inside a box insi-... - A flowchart
Node(v1, pointer-)-> Node(v2, pointer2-)->Node(v3)
One points to another points to another until arrive @ no pointer - Node vs Wrapper
- node: self, next
- wrapper: front, size, back
- Append/Prepend/Delete
- change related variables
- Prepend: 1st, 1st's next, size
- Append: (if not first) oldLast's next, last, size
- Delete: oneInFront's next, size
Usable Code/Miscellaneous:
- A subclass of std lib class cannot simple overwrite methods of SUPER
- super.method() //parent class's method
- random
- import random (package)
- random.randint (smallest, largest)
- inclusive
- list.insert(i,x) insert @i before original x
- Abstract Classes: Simple API for all the child classes to be file under
- basically a container
- convenient
- no var/fn of its own
- var_ //distinguish names from std py names
- isinstance(var, type) vs type(var).__name__
- walk-a-list:
- current = first
- while!=last:
- current=next
- assertion
- bool fn, a checking statement
- crash if false
- __contains__ maps to "in"
- __repr__ maps to return print value
- def __repr__(self):
- return "Ahaha %s nope %s" %(self.x, self.y)
- >>> var
- Ahaha selfXval nope selfYval
- __getitem__ enables printing parts
- print(LinkedList[0:3])
No comments:
Post a Comment