Question: For a Python programming excercise, I need to create a class Graph with attributes Nodes and Edges. Both these attributes are lists. The list of edges is a list of tuples, where both elements of the tuple are elements of the set of the list of nodes. For example, if g is a Graph, then a valid population of g would be:
g.nodes = [1,2,3,4] and
g.edges = [(1,2),(2,3),(3,4),(4,1)]

I have to create a method called add\_node(self, node) that adds a node to the list of nodes and a method called add\_edge(self, edge) that adds an edge to the list of edges provided that the edge is a tuple and both elements of the tuple are in the list of nodes. add\_edge returns True if
the edge was added and False otherwise.

I wrote the following code:

```
class Graph:
def __init__(self):
    self.nodes = []
    self.edges = []

def add_node(self, node):
    self.nodes.append(node)

def add_edge(self, edge):
 if not isinstance(edge, tuple):
     return False

 for i in edge:
     if not i in self.nodes:
         return False
 else:
     self.edges.append(edge)
 return True

```

Now I have to return a string representation of the class 'Graph', that looks like this ‘(,)’. How can I do this?

Answer: 
The gcc option `-flinker-output=rel`[[1](https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html)] might give you something like what you want. You'd use it to run the linker on your library, doing all the LTO stuff in the scope of your library, and then spit out an object file. To turn this back into a static library you could run `ar` on it [[2](https://www.howtogeek.com/427086/how-to-use-linuxs-ar-command-to-create-static-libraries/)].
I haven't done this myself though and I think the [unity build](https://stackoverflow.com/a/68636019/506073) is the better option.

1. <https://gcc.gnu.org/onlinedocs/gcc/Link-Options.html>
2. <https://www.howtogeek.com/427086/how-to-use-linuxs-ar-command-to-create-static-libraries/>
To benefit from the same optimisations as LTO of a static library would theoretically enable, give your library a **unity build** option.
This uses one source file which includes all other code in the library into a single translation unit where it is subject to the same whole-library inter-procedural analysis that you are looking for. SQLite is an example of a widely used library using this approach, even distributing itself as a single source file which is the result of all these transitive inclusions pre-processed into the [SQLite Amalgamation](https://www.sqlite.org/amalgamation.html). Modern CMake [supports unity builds](https://cmake.org/cmake/help/latest/prop_tgt/UNITY_BUILD.html).