Mar-17-2020, 02:15 AM
(This post was last modified: Mar-17-2020, 02:15 AM by Sigriddenfeta.)
class AdjacencyList: def __init__(self, name=None, info=None): self._name = name # head node name self._info = info # head node info if not self.head().is_empty(): self._tail = AdjacencyList() # empty tail self._edges = Edge() # empty list of edgesI am trying to sort my objects by name in lexicographical order.
I tried to apply the same principles as shown in this article.
My attempt to sort the objects is shown below:
AdjacencyList.sort(key=lambda x: x._name, reverse=True)However my IDE tells me two things.
1. Unresolved attribute reference ‘sort’ for class ‘AdjacenyList’
2. Access to a protected member _name of a class
So any better ideas on how I can do this?

Also the definition of the class "AdjacencyList" can't be changed. (But I can add more to it, i think)
If it matters, I think I want to sort the adjacency list in the same method that add new nodes to the list:
def add_node(self, name, info=None): if self.is_empty(): self.__init__(name=name, info=info) else: node = self while not node._tail.is_empty(): node = node.tail() new_node = AdjacencyList(name, info) node.cons(new_node) AdjacencyList.sort(key=lambda x: x._name, reverse=True)# my attempt to sort, that don't work return self.head()