I have a pretty simple idea in mind but don’t exactly know how to go about doing it. I have two lists of different length (say 50 in one and 200 in the other).
so
len(x) = 50
len(y) = 200
What I want to do is print out some lines where one value from x corresponds to multiple values of y (does not matter if numbers are repeated).
I.e. suppose x = [1,2,3,4]
y = [7,8,9,10,11,12,13,14,15,16,17]
I want to print out:
1: 7
1: 8
1: 9
1: 10
2: 11
2: 12
2: 13
3: 14
3: 15
3: 16
4: 17
Randomization of values from y does not really matter.
It does not matter how many multiple values get printed out for each value of x. I am basically trying to write a sql script of inserting multiple elements from one table into another and using python to write the script.
I know this can be done by simply iterating over the smallest list and having multiple f.write() statements while incrementing some variable to have multiple values of y associated to a single value of x. But this does not cover all the values of y and looks kind of silly. Is there a better way to go about doing this?
Edit: For the question where how I came up with the association of keys to values, it does not really matter how many values 1 key is associated with (an upper bound of 8 exists). There can be only 1 value or multiple (up to 8). Then again, there can be repetitions of values between keys (i.e. in my example there is not but key 4 can say have values 7/8 also)
Try this Python solution: