From: Michael Orlitzky Date: Mon, 5 Nov 2012 21:45:01 +0000 (-0500) Subject: Allow tuples to be passed in square brackets. X-Git-Url: https://gitweb.michael.orlitzky.com/?a=commitdiff_plain;h=db04929f99b60f0f2fc587c4b102e11a087b5aa6;p=sage.d.git Allow tuples to be passed in square brackets. --- diff --git a/mjo/symbol_sequence.py b/mjo/symbol_sequence.py index 4384427..7f6c9db 100644 --- a/mjo/symbol_sequence.py +++ b/mjo/symbol_sequence.py @@ -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):