Giving that I have this link https://website.com/files/2019/08/2/1-screenshot-1-1.png
And that I want to generate a list of links, with a start and end row, like [1-2] and [3-4]
For example :
https://website.com/files/2019/08/2/1-screenshot-1-3.png
https://website.com/files/2019/08/2/1-screenshot-1-4.png
https://website.com/files/2019/08/2/1-screenshot-2-3.png
https://website.com/files/2019/08/2/1-screenshot-2-4.png
etc.
How should I do?
CodePudding user response:
regex
is not needed - you could do as follows:
my_link = 'https://website.com/files/2019/08/2/1-screenshot-{:d}-{:d}.png'
links = [my_link.format(number1, number2) for number1 in range(1, 3) for number2 in range(1, 3)]
print(links)
or
links = [f'https://website.com/files/2019/08/2/1-screenshot-{number1}-{number2}.png' for number1 in range(1, 3) for number2 in range(1, 3)]
print(links)
OUTPUT
['https://website.com/files/2019/08/2/1-screenshot-1-1.png', 'https://website.com/files/2019/08/2/1-screenshot-1-2.png', 'https://website.com/files/2019/08/2/1-screenshot-2-1.png', 'https://website.com/files/2019/08/2/1-screenshot-2-2.png']