Skip to content

Instantly share code, notes, and snippets.

@mxml-barmstrong
Created March 14, 2013 05:35
Show Gist options
  • Save mxml-barmstrong/5159071 to your computer and use it in GitHub Desktop.
Save mxml-barmstrong/5159071 to your computer and use it in GitHub Desktop.
SliceDict
class SliceDict(dict):
def __getitem__(self, item):
if isinstance(item, slice):
return self.get(item.start, item.stop)
return super(SliceDict, self).__getitem__(item)
>> d = SliceDict()
>> d['a'] = 1
>> d['a']
1
>> d['b']
KeyError: 'b'
>> d['b':10]
10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment