Interacting all items in a list

0

I have the following situation:

I have 4 numerical lists ranging from 1 to 30. Eg:

AP_X = [1,2,3,4,5...30]
AP_Y = [1,2,3,4,5...30]
demanda_X = [1,2,3,4,5...30]
demanda_Y = [1,2,3,4,5...30]
  • I have another empty list called distancia that will receive the result of these interactions.

    distancia = []
    
  • Lists AP_X and AP_Y represent the coordinates of a point and the demandas_X and demanda_Y lists represent the coordinates of another point.

  • I need to make every point AP(x,y) match every point demanda(x,y) .

  • For example:

    distancia = [1,1,1,1 | 1,1,2,2 | 1,1,3,3 |...| 2,2,1,1 | 2,2,2,2| ...| 30,30,1,1 | 30,30,2,2 ]
    

I do not know if it was clear, but I need to combine all AP(x,y) with all demanda(x,y) .

Thanks in advance for the help.

    
asked by anonymous 07.03.2017 / 00:35

1 answer

0
AP_X = [1,2,3,4,5,30]
AP_Y = [1,2,3,4,5,30]
demanda_X = [1,2,3,4,5,30]
demanda_Y = [1,2,3,4,5,30]

ap = list(zip(AP_X, AP_Y))
demanda = list(zip(demanda_X, demanda_Y))

distancia = []

for i in ap:
  for j in demanda:
    distancia.append((i, j))

print(distancia)

This code prints the following result:

[((1, 1), (1, 1)), ((1, 1), (2, 2)), ((1, 1), (3, 3)), ((1, 1), (4, 4)), ((1, 1), (5, 5)), ((1, 1), (30, 30)), ((2, 2), (1, 1)), ((2, 2), (2, 2)), ((2, 2), (3, 3)), ((2, 2), (4, 4)), ((2, 2), (5, 5)), ((2, 2), (30, 30)), ((3, 3), (1, 1)), ((3, 3), (2, 2)), ((3, 3), (3, 3)), ((3, 3), (4, 4)), ((3, 3), (5, 5)), ((3, 3), (30, 30)), ((4, 4), (1, 1)), ((4, 4), (2, 2)), ((4, 4), (3, 3)), ((4, 4), (4, 4)), ((4, 4), (5, 5)), ((4, 4), (30, 30)), ((5, 5), (1, 1)), ((5, 5), (2, 2)), ((5, 5), (3, 3)), ((5, 5), (4, 4)), ((5, 5), (5, 5)), ((5, 5), (30, 30)), ((30, 30), (1, 1)), ((30, 30), (2, 2)), ((30, 30), (3, 3)), ((30, 30), (4, 4)), ((30, 30), (5, 5)), ((30, 30), (30, 30))]

Where each item is of the format ((AP_X, AP_Y), (demanda_X, demanda_Y))

Does it fit or need to be in the AP_X, AP_Y, demanda_X, demanda_Y format?

    
07.03.2017 / 01:18