A few little corrections or explanations inline below...
On 10/23/10 8:34 AM, Francois Maltey wrote:
Rolandb wrote :
test=((k2,k1) for k1 in xrange(2,4) for k2 in xrange(1,k1) if
gcd(k1,k2)==1)
print [t for t in test]
print [t for t in test]
[(1, 2), (1, 3), (2, 3)]
[]
I begun to confuse lists L with [...] we can free change :
one change one term by L[1]=123, and change the length by
L[3:4]=[7,6,8], or del, or L.pop(), ...
And tuple with (...) as T=(12,13,14,15) it's impossible to change.
A void tuple or a void list are [] and ()
Actually, the empty tuple is (,)---you mention why in this next sentence:
A tuple with one element is (123,) with a comma, because (123) == 123,
the integer.
I can translate a tuple to a list by [t for t in T]
or list(T)
I can translate a list to a tuple by tuple(L)
The syntax (x for x in L) and (x for x in T) aren't translations to a
tuple, but create a generator (or iterator)
An iterator is "an object" with a method .next() that answers the next
term after each call, and () at the end.
I think it actually raises a StopIteration error at the end.
tuple ("an_interator") and list ("an_iterator") enumerate all the NEW
elements of an iterator.
list... and [x for x in ...] seems equal.
That sounds right, depending on what you mean by '...', of course.
In Sage there are 4 ??range(n) function :
range(n) creates the list [0,1,2,...,n-1] of the Sage int (short integer
of Python, until +/- 2^31-1)
range() is a python function that creates python ints, which actually
are arbitrarily big:
sage: a=int(2^34)
sage: range(a,a+2)
[17179869184, 17179869185]
Thanks,
Jason
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org