Ask Your Question
2

Graph sorting problem

asked 2023-06-13 22:02:54 +0200

Josef gravatar image

updated 2023-06-14 14:20:12 +0200

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?

edit retag flag offensive close merge delete

Comments

Welcome to Ask Sage! Thank you for your question.

slelievre gravatar imageslelievre ( 2023-06-14 09:32:13 +0200 )edit

1 Answer

Sort by » oldest newest most voted
2

answered 2023-06-14 11:28:10 +0200

FrédéricC gravatar image

updated 2023-06-14 14:19:38 +0200

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]
edit flag offensive delete link more

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: 2023-06-13 22:02:07 +0200

Seen: 198 times

Last updated: Jun 14 '23