Home > Software design >  Create a loop that puts a word from the list into the link
Create a loop that puts a word from the list into the link

Time:01-10

I have created a sample list of list1 = ["a", "b", "c", "d"]. I would like to create a new list with a loop, in which the items from list1 would be saved, connected with an https link. In list2, the items in the list would look like this: "https://www.google.com/a", "https://www.google.com/b" .... How to do is in python3?

CodePudding user response:

You can do:

base_url = 'https://www.google.com/'
list1 = ["a", "b", "c", "d"]
list2 = [f"{base_url}{item}" for item in list1]
  •  Tags:  
  • Related