Skip to content

Instantly share code, notes, and snippets.

@piotr-piatkowski
Created September 20, 2016 09:03
Show Gist options
  • Save piotr-piatkowski/3f66df430d56119e6240bc34961617e1 to your computer and use it in GitHub Desktop.
Save piotr-piatkowski/3f66df430d56119e6240bc34961617e1 to your computer and use it in GitHub Desktop.
>>> 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