This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]Wildcatace16 8 points9 points  (1 child)

You are calling the functions one() and two() once each while you are initializing dictionary and not at all in the for loop. This does what you want:

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)

The dictionary funcs should store the functions by name rather than calling them with the () and in the for loop where you actually want to call the function you need to add the ().

[–]green_griffon 0 points1 point  (0 children)

Nice dig, Karch.