Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Iterative printing over two data types in Python

Tags:

python

I often browse freely-available art on the web. Actually, I can't think of a better use for the internet than to turn it into a gigantic art gallery. When I encounter a set of pieces I quite like, I download them all to my hard drive. wget makes that easy, especially in combination with Python's print function, and I use this all the time to make a list of URLs that I then wget. Say I need to download a list of jpegs that run from art0 to art100 in the directory 'art,' I just tell python

for i in range(0,101):
    print "http://somegallery/somedirectory/art", i

So, this is probably a fairly simple operation in Python, and after a find-and-replace to remove whitespace, it's just a matter of using wget -i, but in days before I knew any Python I'd slavishly right-click and save.

Now I've got a bunch of files from Fredericks & Freiser gallery in New York that all go a(1-14), b(1-14), c(1-14), etc., up to the letter g. I could do that in 7 goes, and it would take me less time than it took to write this SO question.

That said, I want to deepen my knowledge of Python. So, given the letters a-g, how do I print a mapping of each letter to the integers 1-14?

like image 327
magnetar Avatar asked Jul 12 '26 05:07

magnetar


1 Answers

for i in ['a','b','c','d','e','f','g']:
    for j in range(1,15):
        url = BASE_URL + i + str(j)
        print url

Is that what you are looking for?

like image 160
Senthil Kumaran Avatar answered Jul 14 '26 18:07

Senthil Kumaran



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!