tegge-classroom / STAT2984-2018

STAT 2984: Statistical Programming I - Spring 2018
1 stars 13 forks source link

Question 8 #22

Open apappy56 opened 6 years ago

apappy56 commented 6 years ago

I have been working on this question for a while but i still do not understand how to get the values for each factor into a list on the dictionary. You said use the enumerate function but I don't know exactly where to put it

matter698no2 commented 6 years ago

You'd want to make a loop with a conditional bit inside it to check if the factor is already in the dictionary and append it the value if it is.

[loop]
    if [factor] in [dictionary]:
        [dictionary[factor]].append([value])

If the factor isn't in the dictionary already, you're gonna want to initialize the factor with the initial value in a list.

    else:
        [dictionary[factor]] = []
        [dictionary[factor]].append([value])

as long as you can keep track of the index for both the factor and value in each list, this should do the trick