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 ()
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]
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.

tuple ("an_interator") and list ("an_iterator") enumerate all the NEW elements of an iterator.

list... and [x for x in ...] seems equal.

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) xrange(n) creates an iterator for the same int. So Python doesn't create (maybe very) long list, but only a loop.

srange(n) and sxrange(n) use the Sage Integer (from a Ring) not the Python Int.
You translate one to the other by int(n) or Integer(n).

Is there other main ideas I forget ?

Francois (in France)

--
To post to this group, send email to sage-support@googlegroups.com
To unsubscribe from this group, send email to 
sage-support+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org

Reply via email to