So I have this two list, one with cities and one with lists of other infos. I would like to insert the name of the cities in index 0 of each list of the second list. Problem is at the end I have only one city name that is printed (the last one). Can somebody help me out with this ? Thank you !
cities = ["Paris", "London", "New York"]
data = [
["", "", "", "", 1, 1, "Buildings"],
["", "", "", "", 2, 1, "Streets"],
["", "", "", "", 3, 1, "Avenues"],
["", "", "", "", 1, 2, "Buildings"],
["", "", "", "", 2, 2, "Streets"],
["", "", "", "", 3, 2, "Avenues"],
]
result = []
counter = -1
while counter != len(cities) - 1:
counter += 1
number = -1
while number != len(data) - 1:
number += 1
data[number][0] = cities[counter]
result.append(data[number])
print(result)
gives me
result = [['New York', '', '', '', 1, 1, 'Buildings'],
['New York', '', '', '', 2, 1, 'Streets'],
['New York', '', '', '', 3, 1, 'Avenues'],
['New York', '', '', '', 1, 2, 'Buildings'],
['New York', '', '', '', 2, 2, 'Streets'],
['New York', '', '', '', 3, 2, 'Avenues'],
# (and so on)
]
while I'd rather have
result = [['New York', '', '', '', 1, 1, 'Buildings'],
['Paris', '', '', '', 2, 1, 'Streets'],
['Paris', '', '', '', 3, 1, 'Avenues'],
['Paris', '', '', '', 1, 2, 'Buildings'],
['Paris', '', '', '', 2, 2, 'Streets'],
['Paris', '', '', '', 3, 2, 'Avenues'],
['Paris', '', '', '', 1, 1, 'Buildings'],
['London', '', '', '', 2, 1, 'Streets'],
['London', '', '', '', 3, 1, 'Avenues'],
['London', '', '', '', 1, 2, 'Buildings'],
['London', '', '', '', 2, 2, 'Streets'],
['London', '', '', '', 3, 2, 'Avenues'],
['London', '', '', '', 1, 1, 'Buildings'],
['New York', '', '', '', 2, 1, 'Streets'],
['New York', '', '', '', 3, 1, 'Avenues'],
['New York', '', '', '', 1, 2, 'Buildings'],
['New York', '', '', '', 2, 2, 'Streets'],
['New York', '', '', '', 3, 2, 'Avenues']
]
Thank you