From db04929f99b60f0f2fc587c4b102e11a087b5aa6 Mon Sep 17 00:00:00 2001 From: Michael Orlitzky Date: Mon, 5 Nov 2012 16:45:01 -0500 Subject: [PATCH] Allow tuples to be passed in square brackets. --- mjo/symbol_sequence.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) 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): -- 2.44.2