-
-
Save piotr-piatkowski/3f66df430d56119e6240bc34961617e1 to your computer and use it in GitHub Desktop.
This file contains 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, n): self.name = n | |
... def getName(self): return self.name | |
... | |
>>> n = Node('abc') | |
>>> n.getName() | |
'abc' | |
>>> node('xyz') | |
<__main__.Node object at 0x7f7dbc033f50> | |
>>> def node(name): return Node(name) | |
... | |
>>> n = node('xyz') | |
>>> n.getName() | |
'xyz' | |
>>> {x.getName(): x for x in map(node, ["aaa", "bbb"])} | |
{'aaa': <__main__.Node object at 0x7f7dbc03d0d0>, 'bbb': <__main__.Node object at 0x7f7dbc03d110>} | |
>>> Node.__repr__ = lambda(self): "Node('{}')".format(self.getName()) | |
>>> {x.getName(): x for x in map(node, ["aaa", "bbb"])} | |
{'aaa': Node('aaa'), 'bbb': Node('bbb')} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment