Data Interwine

1st list [A,B,C,D,E,F,G]
2nd list [1,2,3,4]

How to put every n item in the 2nd list after every m items in the 1st list?

If n=1, m=1, the result should be [A,1,B,2,C,3,D,E,F,G]
If n=1, m=2, the result should be [A,B,1,C,D,2,E,F,3,G]
If n=2, m=1, the result should be [A,1,2,B,3,4,C,D,E,F,G]
If n=2, m=2, the result should be [A,B,1,2,C,D,3,4,E,F,G]

You need something to indicate how the values should be assigned. If these are all unique values, a dictionary would be an appropriate approach, e.g.:

{'A': 1,
 'B': 2,
 'C': 3}

For your first example, the Python zip() function would work well, e.g.:

L1 = ['A', 'B', 'C']
L2 = [1, 2]
L3 = zip(L1, L2)

But for your second example, it is unclear how the value assignment is dictated. Why are ‘B’ and ‘D’ the only keys being assigned values?

Thanks for the suggestion.
For now, they are unique values.

Update:

  1. I figure that out, hope it will help someone.
  2. There should be more elegant ways to do this, please share if possible.
    Capture