Reputation: 569
I would like to change the URL by iterating through a list. Any suggestions?
For example,
Let's say the URL is www.example/chi.com
The list of URLs is ['chi', 'den', 'lac']
The desired output that I am looking for is:
www.example/chi.com
www.example/den.com
www.example/lac.com
This is the code that I have so far:
url = "www.example"
team = ["chi", 'den', 'lac']
dot_com = ".com"
for t in team:
print(t)
print("{}/{}{}".format(url, t, dot_com))
Unfortunately the output that I have now looks like:
chi
den
lac
www.example/lac.com
Any help would be greatly appreciated. Thank you!
Upvotes: 0
Views: 945
Reputation: 569
I was able to complete this question in the preferred method thanks to @mapf and @Jab.
Here is the answer on printing multiple urls:
url = 'www.example'
teams = ['chi', 'den', 'lac']
dot_com = '.com'
for t in teams:
print('{}/{}{}'.format(url, t, dot_com))
Upvotes: 0
Reputation: 27515
Why not just format them as you loop through them:
url = "www.example"
team = ["chi", 'den', 'lac']
for t in team:
print(f"{url}/{t}.com")
Upvotes: 1