Skip to content

Instantly share code, notes, and snippets.

@florentx
Created October 18, 2013 07:55
Show Gist options
  • Save florentx/7037988 to your computer and use it in GitHub Desktop.
Save florentx/7037988 to your computer and use it in GitHub Desktop.
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