Posts

Showing posts from 2017

a useless stack dictionary python

Image
Update: 10-6-19  Added code blocks, realized that my ascii used for describing the link between nodes [<--- value --->]  breaks my code blocks even with <pre><code>  So I'll have to go back to my linked lists and make sure I didn't break them, because I know I used this ascii in them too. Why create a useless stack dictionary? I've found a lot of times with endeavors in life, the better question is, why not...? And besides.... I wanted to draw an octopus for a couple of my favorite people. Also... spam and eggs. Also... If I'm going to see if I can replicate how this damned thing works, why not pick something that should be pointless and nothing like the original?? It can't really do anything but horde tuples... but, like I said... useless. Also... It was fun. Why not. An octopus first.....                                       Here's t...

a use for my string maker

With a lot of help from Zed.... I finally got a grasp on this dictionary thing.... The hash will assign some crazy integer to a string....  the modulo will constrain it to a number within the realm of the number of items in my list..... For testing my strings,  I found a use for my string maker.... this thing: def create_variable_large(count, container):     #a - odd     #b - even     var = "wp"     var2 = "pw"     foo = "gr"     foo2 = "rg"     bar = "te"     bar2 = "et"     spam = count     while spam > 0:         if spam < 10 and spam > 0:             if spam % 2:                 var = var + 'b'                 var2 = var + 'a'             else:           ...

playing with dictionaries python

Image
list => key look up Update: 9-2-2021  Took the extra newlines out of the code block, changed title, might tinker a bit. Update: 9-10-19 Putting the python into a code block for easier viewing.  I was doing this experiment while working with LearnMorePythonTheHardWay by Zed Shaw.  The book really pushed me to dissect things and figure them out and will be forever grateful for it. I highly recommend the learn python the hard way books to anyone seeking to learn python or even code for the first time. Update: 1-4-18  A little thing.  Added a node ident... and a _length()  not much. *added a get_ident too...* Thinking about making this doubly linked.  Later it would be more flexible.  Still not so sure how I feel about if manipulating data makes it prone to corruption. Someone told me it doesn't... but it just seems like anything in this world would be prone to damage/corruption the more it gets tinkered with... It's just the nature of th...

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 ...

Something to do while I wait on Doctor Who

Got some more fix's for my DLList done.  I wasn't going to touch any code for the holidays... but the kids are all busy playing with gifts, and everyone else is off socializing.  I'm waiting patiently for the Doctor Who Christmas special.....  <  so so... calmly waiting >....  A female Doctor Who!!!!! ARE YOU FRICKEN KIDDING ME! I'M going to lose my mind I'm so excited.  I'm not a super fan, but seriously, my dad had me watching doctor who when I was a kid and it was on the public broadcasting service channel..... So,  I got the  set_sides() into my swap_left()  and I got the swap_left() doing the swapping of when there is only a begin and end node in the list.    I think the reason it was all getting rejected before was because my quicksort was so wonky, that I kept trying to give it nodes that didn't exist.  I am going to still try and get that version of the quicksort working too, now that I have that nifty lit...

quicksort with swap nodes

She works!!!  with the swap nodes..... I still want to try it with a DLList that contains more then just a data.value....  But in theory it should work just the same...... ## https://en.wikipedia.org/wiki/Quicksort ##  Watched Zeds video and got the just data version working,  then put my swap_any() in.  It worked.  I had a templist at first, but it wasn't necessary.  I'm going to tinker some more.  It all hinged on the 'get_node'. (Zeds)  I kept trying to keep track of what node I was on while the sorting was happening...  that made it impossible to navigate through the list properly when nodes where swapped.  Jeeesum Crow... all of that. It was just that simple little thing. from ex16DLL import* from random import randint def random_list(count):     numbers = DLList()     for i in range(count, 0, -1):         newnumber = randint(0, 100)         number...

so wrong....

I finally watched the solution video for the quicksort I've been thrashing my head on for two weeks.....  What I'm trying to do..... might not be possible..... The way the solution is done for class is by simply swapping out the data values... Not the nodes at all..... I was trying to swap out the entire nodes....   Nice to know.  Wondering if what I am trying to do is still possible.  Not even sure. I could scream.  I could have had this information weeks ago.... but it's my own fault. Is it worth it to keep trying?  If no one does it this way, is it even worth it???? What would be the purpose other then doing something I can't seem to find anyone else doing?  If I have a doubly linked list,  and it has a data value that is an integer... and three other datas that are not... names, status, locations ..  and I sort the list by the data values the way that the given solution is....  then the nodes contain data that are not ma...

swap any node Doubly linked list, python

Update: 12-23-17 Found a bug, adding a fix. The first if, depends on the node1 or node2 having a prev,  and they may or may not.  I tried adding this function set_sides() to my swap_left(self) also and it kept rejecting it... will figure that out later.   Christmas is here, and trying to quicksort this doubly linked list.... is driving me mad.... Does anyone actually sort a doubly linked list inside a doubly linked list with this swap method?? Happy joyful whatever holidays you may celebrate,  and Merry Christmas too! I'll be adding this to my old Doubly Linked List post. It uses my swap_left method for if nodes are next to each other... I will go and see if I can combine these after I get the quicksort figured out.  I'm sure it's possible, but I'm debating if they should be combined. Another one of those, I don't know enough about how these lists are used and manipulated to know if it's a good idea to put that much control over the list into one m...

illustration, doubly linked list

Image
The signs my little monsters are holding, are not the same thing as the chains connecting them. Me,  trying to visualize a doubly linked list.....

node swap for doubly linked list python

Still working on my quick sort. I think I got this all shiny.  Will be going to the Doubly Linked List post to add it in. It will swap left or right.  end or begin.  I've been using it on large randomly generated lists without a problem.  Well, without a problem NOW. I had so many gremlins pop up making this thing work... The order in which the links are set are soooo touchy..... bull in a china shop. Throw a match into the oxygen chamber and everything goes to hell. Anyhoo.   Here it is. If anyone happens to spot anymore of those little bastards that threw all the monkey wrenches at me, feel free to point them out.  I'd love to get my hands on them. Oh and I just realized.... someone might want to swap two items on a list.... if there are just an end and a begin node....  I should add a swap for that..... But that seems like it could lead to REALLY big gremlins.... Troll sized, fire breathing, puppy eating gremlins..... ######### s...

recursive function and merge sort on doubly linked list

Update : 12-17   got someone to explain a few things to me while I was trying to get quick sort to work on the doubly linked list....  I have to redo the merge sort.   The whole node needs to be merged/copied, not just the data/value.  For example... what if the node had more in it then just a numerical value?  then when you sorted it, that data would be lost.  Buger off logical know it all mudder son's a nut bogs.   No , but really.  Had no idea.  So, once I get the swap() method figured out for my doubly linked list, and get that into my quick sort and functioning, I'll come back and fix this all up too.   I guess this still works to show someone how to do it theoretically.      < Tired of the gremlins lurking in my machine... I swear they sneak up...  push buttons ... and type stuff in when I'm not looking. >  So I finally got my merge sort for my class done.  I stumbled for ...

making strings to put in a Doubly linked list

Image
OK, I have no idea what purpose this will serve yet.  I was trying to find a way to sort data outside of the linked lists today with no results... but I did make this happen. Update has the way easier python way to make random strings Update: 4-23-18 Much easier way to make random strings: import random stringsize = 10 x = ''.join(random.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(stringsize)) print(x) here is the method: My goal was to try and give new nodes unique names and then sort them out.... but I realized, how do I sort through them with nothing to contain them?   So this method was made from that.  Don't know if I'll use it for anything, so off it goes to the archives. The first one would be a one off, in a loop that just wanted to create a variable based on the given count given.  Like say,  10 times in the for loop, or the while loop ran 11 times... so on. def create_variable_small(count):     # I'...

experimental linkedlist dictionary python

12-10-17   Added my experiment at the bottom. You know when you look at something, and it's like... I know it's wrong in some way... I just have to figure it out.... I'm not posting what I did today.  I just look at it like,  This has to be some sort of wrong. It's a singly linked list in a doubly linked list,  a node inside a node.   I don't have a lot done with it, I know it's actually functioning,  but I need to work out a graphical like I did with my other lists, because it's really hard to see the guts at the moment. I just keep thinking... this has to be wrong.  Like,  there has to be a reason NOT to do this.  It just seems like a bad thing. Lets not throw a match into the highly flammable liquid type situation.  I don't know yet.  I'm going to play with it a little more tomorrow,  just as a tinker project, but then if Zed is available tomorrow I'll ask if it's worth pursuing as a learning device, or if...

simple Queue in python

The instructions say,  enter data from the beginning, tail of the list, and remove it from the back/end head of the list....  but I really have a hard time keeping the terminology correct.  When your adding the second item, data into the list, you have to set the link in the head/end ...  creating the new node, and setting it as the self.tail.... is that what they mean by 'entering the data'?  isn't the data being created in the python compiler?  Anyways, questions for another time I think.  Here it is!  Bare bones.   Next up in class is 'bubble sort'.   That looks like fun.  It's almost the weekend and I'm downloading Final Fantasy online.  I'm sure I'll be coding.  Especially since I want to try and make something  like this with these nodes:    ( node[ (namespace)     ---->   [data][data][data]] ) ----->(node[(namespace) ---->[data][data][data]]) PYTHON Q...