]> gitweb.michael.orlitzky.com - sage.d.git/commitdiff
Allow tuples to be passed in square brackets.
authorMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Nov 2012 21:45:01 +0000 (16:45 -0500)
committerMichael Orlitzky <michael@orlitzky.com>
Mon, 5 Nov 2012 21:45:01 +0000 (16:45 -0500)
mjo/symbol_sequence.py

index 43844271876b2b935857dfd3f1d679f57c05d4ba..7f6c9db7622a2e360a964dfda7cd721c01f885f9 100644 (file)
@@ -77,6 +77,13 @@ class SymbolSequence:
         sage: a[0:5]
         [a0, a1, a2, a3, a4]
 
+    If for whatever reason you prefer square brackets, the following
+    also works::
+
+        sage: a = SymbolSequence('a')
+        sage: a[1,3]
+        a13
+
     TESTS:
 
     We shouldn't overwrite variables in the global namespace::
@@ -156,6 +163,9 @@ class SymbolSequence:
 
 
     def __getitem__(self, key):
+        if isinstance(key, tuple):
+            return self(*key)
+
         if isinstance(key, slice):
             # We were given a slice. Clean up some of its properties
             # first. The start/step are default for lists. We make
@@ -173,8 +183,8 @@ class SymbolSequence:
             # If the user asks for a slice, we'll be returning a list
             # of symbols.
             return [ self(idx) for idx in range(start, key.stop, step) ]
-        else:
-            return self(key)
+
+        return self(key)
 
 
     def __call__(self, *args):