graph and dict possible bug or user error?

14 views
Skip to first unread message

kcrisman

unread,
Aug 7, 2014, 1:34:36 AM8/7/14
to sage-s...@googlegroups.com
Consider

plot(Graph({1:[2],1:[3]}))

I would expect two edges.  Instead the vertex 2 isn't even there.  Is this a bug or a feature?  The documentation for this way of entering graphs is pretty terse so I was quite surprised by this outcome.

- kcrisman

Nils Bruin

unread,
Aug 7, 2014, 2:03:11 AM8/7/14
to sage-s...@googlegroups.com

Sage never comes into play here. Dictionary literals ("Dictionary displays" in official python lingo) are defined to be evaluated left-to-right, in order. See https://docs.python.org/2/reference/expressions.html#dictionary-displays

kcrisman

unread,
Aug 7, 2014, 2:56:59 AM8/7/14
to sage-s...@googlegroups.com
Consider

plot(Graph({1:[2],1:[3]}))

I would expect two edges.  Instead the vertex 2 isn't even there.  Is this a bug or a feature?  The documentation for this way of entering graphs is pretty terse so I was quite surprised by this outcome.

Sage never comes into play here. Dictionary literals ("Dictionary displays" in official python lingo) are defined to be evaluated left-to-right, in order. See https://docs.python.org/2/reference/expressions.html#dictionary-displays

 "This means that you can specify the same key multiple times in the key/datum list, and the final dictionary’s value for that key will be the last one given."

Okay, that is very helpful, and something I'm a little surprised I haven't seen before - I never even checked the dict!  Luckily for my actual application I could just move my filter somewhere else to avoid this issue.  Thanks!
Reply all
Reply to author
Forward
0 new messages