write codes in python replace (in your data structure) all city names with a unique name that contains the word "City" followed by a unique number. e.g. City1 City2 City100 City101 City102 ...
时间: 2024-04-14 12:30:27 浏览: 9
Certainly! Here's an example code in Python that replaces city names in a data structure with unique names containing the word "City" followed by a unique number:
```python
data_structure = ['New York', 'London', 'Paris', 'Tokyo', 'Sydney']
counter = 1 # Initialize counter variable
for i in range(len(data_structure)):
unique_name = f'City{counter}' # Generate unique name
data_structure[i] = unique_name # Replace city name with unique name
counter += 1 # Increment counter
# Print the updated data structure
for city in data_structure:
print(city)
```
Output:
```
City1
City2
City3
City4
City5
```
In this example, the code iterates through the data structure, replaces each city name with a unique name generated using the counter variable, and increments the counter for the next unique name. Finally, it prints the updated data structure with the new city names.