#19319: iterator over pairs on diagonals a la Cantor pairing
-------------------------------------+-------------------------------------
Reporter: dkrenn | Owner:
Type: enhancement | Status: needs_review
Priority: major | Milestone: sage-6.9
Component: misc | Resolution:
Keywords: | Merged in:
Authors: Daniel Krenn | Reviewers:
Report Upstream: N/A | Work issues:
Branch: | Commit:
u/dkrenn/product_cantor_pairing | 17229c620b4aff47161b725de2ebb4f890cfc2af
Dependencies: | Stopgaps:
-------------------------------------+-------------------------------------
Comment (by ncohen):
Okay. Longer than the first attempt, though
{{{
def product(A,B):
A = iter(A)
B = iter(B)
list_a = []
list_b = []
a_nonempty = b_nonempty = True
while a_nonempty or b_nonempty:
if a_nonempty:
try:
list_a.append(A.next())
except StopIteration:
a_nonempty = False
else:
for b in list_b:
yield (list_a[-1],b)
if b_nonempty:
try:
list_b.append(B.next())
except StopIteration:
b_nonempty = False
else:
for a in list_a:
yield (a, list_b[-1])
}}}
--
Ticket URL: <http://trac.sagemath.org/ticket/19319#comment:14>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sage-trac.
For more options, visit https://groups.google.com/d/optout.