Hello all, I am trying to use range() and for loop function to change the dictionary keys and values.
Expected output result is to create the keys and values of t{} according to the values in f_set.
The expected result is e.g I would like to create f_set[0]=(e.g 5) and f_set[1]=e.g 2 values and get the t output as {(1, 2, 1): 1, (1, 2, 2): 1, (1, 2, 3): 1, (1, 2, 4): 1, (1, 2, 5): 1,(1, 3, 1): 1, (1, 3, 2): 1}. However, the current output is always taking the maximum value fro m f_set as final value. How can I get the t output as I want to create? Thanks for any help.
Expected output result is to create the keys and values of t{} according to the values in f_set.
The expected result is e.g I would like to create f_set[0]=(e.g 5) and f_set[1]=e.g 2 values and get the t output as {(1, 2, 1): 1, (1, 2, 2): 1, (1, 2, 3): 1, (1, 2, 4): 1, (1, 2, 5): 1,(1, 3, 1): 1, (1, 3, 2): 1}. However, the current output is always taking the maximum value fro m f_set as final value. How can I get the t output as I want to create? Thanks for any help.
1 2 3 4 5 6 7 8 9 10 |
N = [ 1 , 2 , 3 ] t = {} f_set = [ 5 , 2 , 1 , 10 , 15 , 1 , 3 , 1 ] for x in N: for y in N: if x is not y: for f in f_set: for f_no in range ( 1 ,f + 1 ): t[x,y,f_no] = 1 print (t) |
Output:{(1, 2, 1): 1, (1, 2, 2): 1, (1, 2, 3): 1, (1, 2, 4): 1, (1, 2, 5): 1, (1, 2, 6): 1, (1, 2, 7): 1, (1, 2, 8): 1, (1, 2, 9): 1, (1, 2, 10):
1, (1, 2, 11): 1, (1, 2, 12): 1, (1, 2, 13): 1, (1, 2, 14): 1, (1, 2, 15): 1, (1, 3, 1): 1, (1, 3, 2): 1, (1, 3, 3): 1, (1, 3, 4): 1, (1, 3, 5): 1, (1, 3, 6): 1, (1, 3, 7): 1, (1, 3, 8): 1, (1, 3, 9): 1, (1, 3, 10): 1, (1, 3, 11): 1, (1, 3, 12): 1, (1, 3, 13): 1, (1, 3, 14): 1, (1, 3, 15): 1, (2, 1, 1): 1, (2, 1, 2): 1, (2, 1, 3): 1, (2, 1, 4): 1, (2, 1, 5): 1, (2, 1, 6): 1, (2, 1, 7): 1, (2, 1, 8): 1, (2, 1, 9):
1, (2, 1, 10): 1, (2, 1, 11): 1, (2, 1, 12): 1, (2, 1, 13): 1, (2, 1, 14): 1, (2, 1, 15): 1, (2, 3, 1): 1, (2, 3, 2): 1, (2, 3, 3): 1, (2,
3, 4): 1, (2, 3, 5): 1, (2, 3, 6): 1, (2, 3, 7): 1, (2, 3, 8): 1, (2, 3, 9): 1, (2, 3, 10): 1, (2, 3, 11): 1, (2, 3, 12): 1, (2, 3, 13): 1, (2, 3, 14): 1, (2, 3, 15): 1, (3, 1, 1): 1, (3, 1, 2): 1, (3, 1, 3): 1, (3, 1, 4): 1, (3, 1, 5): 1, (3, 1, 6): 1, (3, 1, 7): 1, (3, 1, 8): 1, (3, 1, 9): 1, (3, 1, 10): 1, (3, 1, 11): 1, (3, 1, 12): 1, (3, 1, 13): 1, (3, 1, 14): 1, (3, 1, 15): 1, (3, 2, 1): 1, (3, 2, 2): 1, (3, 2, 3): 1, (3, 2, 4): 1, (3, 2, 5): 1, (3, 2, 6): 1, (3, 2, 7): 1, (3, 2, 8): 1, (3, 2, 9): 1, (3, 2, 10): 1, (3, 2, 11): 1, (3, 2, 12): 1, (3, 2, 13): 1, (3, 2, 14): 1, (3, 2, 15): 1}