dictionaries
Started my next lesson on dictionaries in the LMPTHW...
Its so much to learn. I had to ask some questions today, and while I had a lot explained to me I still was left thinking... why in the world are we putting 256 Doubly Linked lists into a doubly linked list? I understand that we don't want the data to be mutable, and that theres a big complicated thing with looking up data in the data storage so that the name lookup needs to be encoded with hash tables and stuff....
I could have kept asking questions, but it felt like I should go explore it on my own. So I started to write a node to store a key and value.... then I was going to write a linked list to hold that.... and then write a dictionary from what Zed gave us in the book. But my gremlins came back. The node I wrote was just like the others, but when I tried it out.... It wouldn't take parameters, and it would ititialize without them...
WTH..... I even made another just like it with different names.... it worked..... copied my DLLNode.... it worked....
I swear to goodness. The gremlins in my computer. Or I'm going mad. Either way, time to walk away from this thing and take a break. Here's what I did. What the hell??
HOW IN THE HELL DID PYTHON not ERROR on that!!!
Found it...................................................
class Something(object):
def __init__(self, top, bottom, shoes):
self.top = top
self.bottom = bottom
self.shoes = shoes
class DicaNode(object):
def __inti__(self, name, value, link):
self.name = name
self.value = value
self.link = link
class DLLNode(object):
# I changed the order so that it would be easier to visualize
# and easier to keep track of.
def __init__(self, prev, value, nxt):
# the first node will have no next or previous
self.value = value
self.next = nxt
# previous
#nope = DLLNode() #would not initialize without parameters
#what = Something() # would not initialize without parameters
hair = DicaNode() # would only initialize if given NO parameters.
print(hair)
Its so much to learn. I had to ask some questions today, and while I had a lot explained to me I still was left thinking... why in the world are we putting 256 Doubly Linked lists into a doubly linked list? I understand that we don't want the data to be mutable, and that theres a big complicated thing with looking up data in the data storage so that the name lookup needs to be encoded with hash tables and stuff....
I could have kept asking questions, but it felt like I should go explore it on my own. So I started to write a node to store a key and value.... then I was going to write a linked list to hold that.... and then write a dictionary from what Zed gave us in the book. But my gremlins came back. The node I wrote was just like the others, but when I tried it out.... It wouldn't take parameters, and it would ititialize without them...
WTH..... I even made another just like it with different names.... it worked..... copied my DLLNode.... it worked....
I swear to goodness. The gremlins in my computer. Or I'm going mad. Either way, time to walk away from this thing and take a break. Here's what I did. What the hell??
HOW IN THE HELL DID PYTHON not ERROR on that!!!
Found it...................................................
class Something(object):
def __init__(self, top, bottom, shoes):
self.top = top
self.bottom = bottom
self.shoes = shoes
class DicaNode(object):
def __inti__(self, name, value, link):
self.name = name
self.value = value
self.link = link
class DLLNode(object):
# I changed the order so that it would be easier to visualize
# and easier to keep track of.
def __init__(self, prev, value, nxt):
# the first node will have no next or previous
self.value = value
self.next = nxt
# previous
#nope = DLLNode() #would not initialize without parameters
#what = Something() # would not initialize without parameters
hair = DicaNode() # would only initialize if given NO parameters.
print(hair)
Comments
Post a Comment