0

I have:

N = a list of numbers from 0-29

A = a list of all alphabet letters.

I want to combine them in order to get all possible permutations of "NAN", from 0a0 up to 29z29

Then, I want to use each one of these "NAN" permutations and get them inside a URL, so I can get something like "http://www.geo.ma/NAN.txt"

import string
import itertools

#Generate the letter list
Alist=list(string.ascii_lowercase)
#Generate the number list
Nlist=list(range(30))

#Combine them in order to get "ABA"
CombinedList=(list((itertools.product(Nlist, Alist, Nlist))))

print(CombinedList)

I got the list, but now I try to get the permutations inside the URL:

for i in CombinedList:
    print('http://www.geo.ma/', i)

But i get http://www.geo.ma/ (29, z, 29) instead of what I'd like to get: http://geo.ma/29z29.txt

If I try to convert the List to string before trying to generate the URLS with StringedList = str(CombinedList), python just uses each one of the characters to generate the URLs, so I get things like http://geo.ma/].txt, http://geo.ma/9.txt, http://geo.ma/z.txt, http://geo.ma/).txt, http://geo.ma/).txt, etc.

3 Answers 3

2
baseURL = "http://www.geo.ma/"
for pair in CombinedList:
    N1, A, N2 = pair
    print(f"{baseURL}{N1}{A}{N2}.txt")
Sign up to request clarification or add additional context in comments.

Comments

2

use .join()

for i in CombinedList:
    print('http://www.geo.ma/{}'.format(''.join(map(str,i))))

output:

...

http://www.geo.ma/29z22
http://www.geo.ma/29z23
http://www.geo.ma/29z24
http://www.geo.ma/29z25
http://www.geo.ma/29z26
http://www.geo.ma/29z27
http://www.geo.ma/29z28
http://www.geo.ma/29z29

Comments

0
for i in CombinedList:
    print('http://www.geo.ma/'+str(i[0])+i[1]+str(i[2])+'.txt')

output is

http://www.geo.ma/0a0.txt
http://www.geo.ma/0a1.txt
http://www.geo.ma/0a2.txt
http://www.geo.ma/0a3.txt
http://www.geo.ma/0a4.txt
http://www.geo.ma/0a5.txt
http://www.geo.ma/0a6.txt
http://www.geo.ma/0a7.txt
http://www.geo.ma/0a8.txt
...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.