Add multiple unknowns to a string in Pyton


I need to add to the line:


four values ​​of possible coordinates instead of "item" value. We have to generate these coordinate values ​​in a loop.

I tried many different options for how to do this, but the program displays a lot of extra values.

My code:

import numpy as np
for item in np.arange(45.024287,45.024295,0.000001):
    coordinates.append("%.6f" %item)
    for item in np.arange(45.024287,45.024295,0.000001):
        coordinates.append("%.6f" %item)
for item in (coordinates):

I need to get this result:


With different coordinates

But I am getting repeated values ​​due to the fact that the loop is in a loop.
Can you tell me how you can substitute several variables in a string without doubling the values?Please

Asked By: AnTiXrI



I remember reading recently something related to your problem. Can’t remember the post, else I’d link it, but I took notes about the beautiful method! So try this:

for item1, item2 in zip(*[iter(coordinates)]*2):
Answered By: Swifty

There’s no need for the coordinates array. Just append to urls in the nested for loop to get all the combinations of item values.

for item1 in np.arange(45.024287,45.024295,0.000001):
    for item2 in np.arange(45.024287,45.024295,0.000001):
Answered By: Barmar
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.