Created
October 18, 2013 07:55
-
-
Save florentx/7037988 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class MagicList(list): | |
def __getitem__(self, key): | |
if not isinstance(key, tuple): | |
return list.__getitem__(self, key) | |
rv = [] | |
for element in key: | |
value = list.__getitem__(self, element) | |
if isinstance(element, slice): | |
rv.extend(value) | |
else: | |
rv.append(value) | |
return rv | |
if __name__ == '__main__': | |
s = "1:2:3:4:5" | |
result = MagicList(s.split(':'))[0,2:6] | |
print(result) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment