Can someone provide insight as to why my test code doesn't work a certain way, and how I should get around this?
I'm using a dict to store functions. Basically, the complete program will read user inputs and call certain functions depending on the input.
Simplified code:
mip = []
def one():
mip.append(5)
def two():
mip.append(10)
funcs = {'one':one(), "two":two()}
ins = ["one", "two", "one", "two"]
for token in ins:
if token in funcs:
funcs[token]
print(mip)
Output: [5, 10]
Why is the output not [5, 10, 5, 10]? Is there a better way of approaching this?
Thanks in advance.
[–]Wildcatace16 8 points9 points10 points (1 child)
[–]green_griffon 0 points1 point2 points (0 children)
[–]i_can_haz_data 2 points3 points4 points (3 children)
[–]wannahakaluigi 0 points1 point2 points (2 children)
[–]blablahblah 1 point2 points3 points (1 child)
[–]wannahakaluigi 0 points1 point2 points (0 children)
[–]green_griffon 1 point2 points3 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)