Showing posts from January, 2018

diagram for delete on a parent node

Took a break from code, came back to my binary tree.  I did my get, and started the remove/delete and got a little stuck. 

The parent node,  which I consider the first branch from the root_node seems to be the biggest hurdle. 

Took me a bit, but I came up with this diagram to show myself where I needed to go for the new parent node.  I'll put the code up when I've written it.  Here's my pic, with some logic written in.

tinker balanced right branch

So this is the code for what I tried to make...
I was trying to make the keys,  akey  coming into the tree be as balanced as possible.  After much head scratching, and a lot of walking away... I decided to set it aside and just do the tree without balancing it... and wow butter.  Especially after going through all this.
I think this worked, but there wasn't a great way to test it.  I had a print method to see what was going on, and it looked like what I wanted it to do, but I have so much to learn, and so much farther to go before I can properly tackle this.

 The whole code would be really confusing.... I had something completely different, and then altered just the right branch to try and figure it out .

tree = BinaryTree(20)
tree.set(21, 'spam')
tree.set(22, 'eggs')
tree.set(23, 'poltry')
tree.set(24, 'cheese')
tree.set(25, 'bubbles')
tree.set(30, 'pump')
tree.set(31, 'chicken')
tree.set(26, 'ham')
tree.set(28, 'coffee&#…

making progress

So I got the old dictionary exercise updated so it uses python lists instead of the doubly linked lists.... 

Here's a test run with the python profile,  on a random list build.

def random_list(alist, count):
    for x in range(0, count):
        number = randint(0, 1000)
        alist.set(number, 'spam')

So all it's measuring is how long it's taking for the dictionary to build the list, compared to my binary search tree.
My tree-thing-pole is slow, but it's ordered.  I ran the test the first few times and forgot to change the median, so it was real real slow.  over 1 sec.   Then I remembered I had to change it according to the numbers I was putting in the list, and it went down to averaging .35 ,  so I'm not feeling to bad about it.  I know I'll still have to fix it so it's nodes only, and make it branch, but I wanted to go back and test what I made before I moved on.
 Picture my last test run:

Here's the dictionary without the doubly linked list:

not a binary tree python

Ok, a little background.  The lesson for class specifically said NOT to look up what a binary tree was, and to try and make one from his english description.  I honestly didn't know what they were supposed to look like,  just that they had a way of sorting stuff out as it went into the structure....  We needed a root BinaryTreeNode,  then the BinaryTree,  where we'd put the data...  and it would have a set(), get(), delete(), and list()
the Node would have a key, value, left, right.  and when the nodes go into the binary tree they would go straight into the structure where they belong, the root node would help decide where the new set data would go somehow.....Oh and it had something to do with that crazy Doubly Linked Dictionary we made...

Realized I didn't account for putting stuff in the list that matched the key of the root node.... adding that in.  Going to pull out my string maker for some testing.
Maybe I wasn't so far off from what it's supposed to do after…

Simple things x=y

Had someone in class ask about this:
Update:  1-21-18  So, playing with the class I made... This does not solve his dilema.  Any changes made to the class will affect the stored object, too.  So time to keep looking.  Python has to have a way to copy an existing object and giving it a new id? Hrmmmm.....

Found this:

>>> x = 5
>>> y = x
>>> y = 0

How do we get y to point to x, and not be assigned to equal x and visa versa?

When the = sign is used, the variables get stored in the same memory space, so kinda like python is making a spot and saying,  all these things are going to be the same thing.   so,  in location 898884848  there is x and y....  any time you say x = True,  all the things in 898884848 are set to True.   Same with y.
y = 'puppies'   all the things in 898884848 are set to 'puppies'.

Python class's.  The niffty storage container. It's own little box to keep…

ok django

This guys tutorials are great, btw.

Used Flask for the class project of building a website, but after watching a few of these and playing with Django, I'm going to go with django.

It has so many things built in,  and so much just sets up for you and they really seem to have it so that anybody can get a running start without a total crash and burn.

Me likey. I can tweak and get more crash and burn on my own thanks, I'd like to just get something running without the scorch.

I'm hoping to have something put up by the end of the day so I can put a link in here.  It won't be much yet, but I want to get something at least on my domain name so it isn't just sitting there empty.  Hope to add an update under here by the end of the day with my link!

1- 20-18
Well, my Digital Ocean IP works, I thought I had my domain name set up right... but getting a 502 err…

A python questionaire game

It's a silly game I made a while back,  Totally rebuilt it.  The old version was when I tried Zed's book the first time and was completely on my own( back when it was a free download).  The orginal had no class's, a crap ton of 'if's'  and honestly... I'm not sure how it ran.  It did, I remember having my friends play it.

Next project setting up my webpage under!

My new game:

from sys import exit

class Psychillogical(object):

def __init__(self, question):
          self.question = question
          self.responses = {}
          self.answers = []

def respond(self, answer):
          result = self.responses.get(answer, None)
def add_responses(self, responses):
def set_answers(self, alist):
          self.answers = alist
  def show_question(self):
def show_answers(self):
          for i in self.answers: