1 | initial version |
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 ant 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)
2 | No.2 Revision |
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 ant 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)