Last active
October 16, 2015 13:29
-
-
Save internetimagery/25462955022f8449fcc8 to your computer and use it in GitHub Desktop.
Mutable Templates
This file contains 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
import collections | |
class Dict(collections.MutableMapping): | |
def __init__(s, *args, **kwargs): | |
s.data = dict(*args, **kwargs) | |
def __getitem__(s, k): return s.data[k] | |
def __setitem__(s, k, v): s.data[k] = v | |
def __delitem__(s, k): del s.data[k] | |
def __iter__(s): return iter(s.data) | |
def __repr__(s): return repr(s.data) | |
def __len__(s): return len(s.data) | |
class List(collections.MutableSequence): | |
def __init__(s, *args, **kwargs): | |
s.data = list(*args, **kwargs) | |
def insert(s, k, v): s.data.insert(k, v) | |
def __setitem__(s, k, v): s.data[k] = v | |
def __getitem__(s, k): return s.data[k] | |
def __delitem__(s, k): del s.data[k] | |
def __len__(s): return len(s.data) | |
def __repr__(s): repr(s.data) | |
class Set(collections.MutableSet): | |
def __init__(s, *args, **kwargs): | |
s.data = set(*args, **kwargs) | |
def __contains__(s, v): return v in s.data | |
def __iter__(s): return iter(s.data) | |
def discard(s, v): s.data.discard(v) | |
def __repr__(s): return repr(s.data) | |
def __len__(s): return len(s.data) | |
def add(s, v): s.data.add(v) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment