@anonymous/DeterminedBlindClownanemonefish
Python3

No description

Files
  • main.py
main.py
class Dict(dict):
  '''
  Override __getitem__ to accept slices
  Slices aren't valid keys to dicts so here we abuse syntax some
  If we're given a slice, treat the start as the key and the stop
    as the default
  '''
  def __getitem__(self, key):
    k = key
    if type(key) is slice:
      k = key.start
      if k not in self:
        return key.stop
    return super().__getitem__(k)
    
d = Dict()
d['a'] = 1
d['b'] = 2
print(d['a'])
print(d['b'])
print(d.get('c'))
print(d['c':])
print(d['c':'Hello, World!'])
Python 3.6.1 (default, Dec 2015, 13:05:11) [GCC 4.8.2] on linux