Ask Your Question
1

How to take an initial segment of the data structure graphs(n) ?

asked 2018-03-08 09:27:10 +0200

Peter Heinig gravatar image

Is there a possibility to access individual elements of the data-structure constructed by the command

graphs(7)

? How to take an initial segment of it?

It seems not to be a list, which presumably is the reason why commands like ' graphs(7)[0] ' or ' graphs(7)[:5] ' are not allowed.

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2018-03-08 11:21:25 +0200

tmonteil gravatar image

updated 2018-03-08 11:22:12 +0200

Such object is called an iterator in the Python world, you will find tons of nice tutorials with examples on the web. For example, if you want a list containing the first 10 elements generated by it, just do:

sage: G = graphs(7)
sage: [G.next() for _ in range(10)]

If you want to iterate over its elements until you find an interesting one, you can do something like:

sage: for g in graphs(7):
....:     if very_interesting_property(g):
....:         do_something_interesting(g)

You can also produce an iterator selectinf the interesting ones:

sage: I = (g for g in graphs(7) if very_interesting_property(g))

and then do:

sage: for g in I:
....:      do_something_interesting(g)
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: 2018-03-08 09:27:10 +0200

Seen: 222 times

Last updated: Mar 08 '18