This week was all about Linked Lists and nodes. I felt relatively calm about the whole topic as it basically sounded like a train, connected at the end of each cars with the next variable.
class LListNode:
"""Node to be used in linked list"""
def __init__(self: 'LListNode', value: object =None,
nxt: 'LListNode' =None) -> None:
"""Create a new LListNode"""
self.value, self.nxt = value, nxt
def __repr__(self: 'LListNode') -> str:
"""String representation of this LListNode"""
return 'LListNode(' + str(self.value) + ', ' + str(self.nxt) + ')'
For each node created, there is a link to the next Node value (self.next) which for me is best understood as the end of a traincar attached to the beginning of the next one.
Danny told us in a slide during lecture that if we omitted __str__, Python should use __repr__ instead in order to convert elements to strings. We also learned that we could use LListNode in order to re-implement stacks.
I found the first part of Assignment 2 to be quite confusing. I think the freedom of ways to tackle the problems were so varied that it kind of left me a little lost looking for the right way to implement all the functions.
Interesting SLOG for this week:
http://lavendercsc148.blogspot.ca/
Second time using this blog for comments but it really just is that good. This week Lavender focused on the second part of Assignment 2 which I wish I had prior to submitting that assignment. Lavender goes in depth describing each cases and how to do it which left me fairly speechless as the code was simple yet extremely effective and I could only wish I would have written it as such. She goes over each case of the regex_match code, which each case being a different regex symbol.
No comments:
Post a Comment