Created
July 22, 2015 18:20
-
-
Save jweinst1/54074c66d000faf69a20 to your computer and use it in GitHub Desktop.
Linked Nodes.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Node (object): | |
| def __init__(self, cargo=0, next=0): | |
| self.cargo, self.next = cargo, next | |
| class NodeList (list): | |
| def __init__(self, head): | |
| self.append(head) | |
| def deeplen(self): | |
| strlst = list(str(self)) | |
| numlist = [s for s in strlst if s != '[' and s != ']' and s != ' ' and s != ','] | |
| return len([int(x) for x in numlist]) | |
| def addtail(self, tail): | |
| value = [tail] | |
| command, length, count = 'self', self.deeplen(), 0 | |
| while count < length-1: | |
| command += str([1]) | |
| count += 1 | |
| command += '.append(%s)' %(value) | |
| eval(command) | |
| return self | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment