Ask Your Question
2

Graph sorting problem

asked 1 year ago

Josef gravatar image

updated 1 year ago

slelievre gravatar image

If I do this in SageMath10.0:

G = Graph()
G.add_vertex('a')
G.add_vertex(1)
print(G.vertices())

I get a deprecation warning but also this error:

File ~/sage/sage-10.0/src/sage/graphs/generic_graph.py:11370, in GenericGraph.vertices(self, sort, key, degree, vertex_property)
  11367     raise ValueError('sort keyword is False, yet a key function is given')
  11369 if sort:
> 11370     return sorted(self.vertex_iterator(degree=degree, vertex_property=vertex_property), key=key)
  11371 return list(self.vertex_iterator(degree=degree, vertex_property=vertex_property))

TypeError: '<' not supported between instances of 'int' and 'str'

According to the documentation, the name of a vertex should be immutable, so an integer and a string should be fine. Is it a bug or am I doing something wrong?

Preview: (hide)

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 1 year ago )

1 Answer

Sort by » oldest newest most voted
2

answered 1 year ago

FrédéricC gravatar image

updated 1 year ago

slelievre gravatar image

Do not mix strings and numbers in the labels of your graph. Make all of them strings, for instance.

Or use

sage: G.vertices(sort=False)
['a', 1]
Preview: (hide)
link

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 1 year ago

Seen: 567 times

Last updated: Jun 14 '23