Hi, On Sat, May 15, 2010 at 5:58 PM, Santanu Sarkar <[email protected]> wrote: > Suppose A=[0,0,1,1,0,1]. How one can reverse this array using commend only?
If A is a list, then the command A.reverse() would reverse your list in place, meaning that it would actually change your list A. On the other hand, there are times when you don't want to change your list, but to get the reverse of the list. In that case, you could use the slice operation [::-1]. Here are some examples to demonstrate what I mean: [mv...@sage ~]$ sage ---------------------------------------------------------------------- | Sage Version 4.4.1, Release Date: 2010-05-02 | | Type notebook() for the GUI, and license() for information. | ---------------------------------------------------------------------- sage: A = [0,0,1,1,0,1]; B = copy(A); A; B [0, 0, 1, 1, 0, 1] [0, 0, 1, 1, 0, 1] sage: A == B True sage: A.reverse(); A [1, 0, 1, 1, 0, 0] sage: A == B False sage: sage: reset() sage: sage: A = [0,0,1,1,0,1]; B = copy(A); A; B [0, 0, 1, 1, 0, 1] [0, 0, 1, 1, 0, 1] sage: A == B True sage: C = A[::-1]; C [1, 0, 1, 1, 0, 0] sage: A == B == C False sage: A == B True sage: A == C False sage: A; C [0, 0, 1, 1, 0, 1] [1, 0, 1, 1, 0, 0] -- Regards Minh Van Nguyen -- 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
