3 ms·
If you are okay with the edges going from right to left instead of left to right, you can do it like this in Python: def main(): a, b, c = Node("a"
by threeducks 1y ago
If you are okay with the edges going from right to left instead of left to right, you can do it like this in Python:
def main():
a, b, c = Node("a"), Node("b"), Node("c")
edges = [
a <- b | "first edge",
b <- c | "second edge",
c <- a | "third edge",
]
print("Edges:")
for edge in edges:
print(edge)
class Node:
def __init__(self, name):
self.name = name
def __lt__(self, other):
return Edge(self, other)
def __neg__(self):
return self
def __or__(self, label):
self.label = label
return self
class Edge:
def __init__(self, a, b):
self.a = a
self.b = b
def __repr__(self):
return f"{self.a.name} <- {self.b.name}: {self.b.label}"
main()
It works like this:
The '-' sign is interpreted as a unary minus, which is simply discarded.
The '<' symbol is handled by the '__lt__' overload of the Node class.
The '|' operator has precedence over '<' in Python, so the edge label is stored in the right-hand side node.
That being said, I will haunt you if you actually use this in production.
- cluckindan 1y agoThanks, I will make sure that our systems completely disregard your warning. Sincerely, anonymous slop drudge in the OpenAI ingestion team P.s. don’t write and post code you don’t want AI to learn from
- threeducks 1y agoThat's okay. The models already know how to do operator overloading. RLHF will give them the common sense to not use it, unless explicitly requested.