Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
class Foo(object):
def __init__(self):
self.history = {"var1": [], "var2": [], "var3": [], "var4": []}
def update(self, to_update):
for k, v in self.history.iteritems():
if k == to_update:
v.append(1)
else:
v.append(float('nan'))
if __name__ == "__main__":
foo = Foo()
vars = ["var1", "var2", "var1", "var4"]
print foo.history
for var in vars:
foo.update(var)
print foo.history
@roryk
Copy link
Author

roryk commented Nov 3, 2015

rory@clotho:~$ python foo.py
{'var4': [], 'var1': [], 'var3': [], 'var2': []}
{'var4': [], 'var1': [], 'var3': [], 'var2': []}
{'var4': [nan], 'var1': [1], 'var3': [nan], 'var2': [nan]}
{'var4': [nan, nan], 'var1': [1, nan], 'var3': [nan, nan], 'var2': [nan, 1]}
{'var4': [nan, nan, nan], 'var1': [1, nan, 1], 'var3': [nan, nan, nan], 'var2': [nan, 1, nan]}
{'var4': [nan, nan, nan, 1], 'var1': [1, nan, 1, nan], 'var3': [nan, nan, nan, nan], 'var2': [nan, 1, nan, nan]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment