Generating a unique key
You can pass str to map rather than a lambda.
You can remove the need for map if you change your third loop to append str(number).
You can use string to remove the need for chr and int in the first three loops. By using:


string.ascii_letters:
abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
string.digits:
0123456789

You can combine all your loops into one string concatenation.
Don't use ; to end lines.
You can define array as a constant outside the function.
I recommend using Python 3, or changing print to be Python 3 compatible.




import random
import string

CHARACTERS = (
    string.ascii_letters
    + string.digits
    + '-._~'
)

def generate_unique_key():
    return ''.join(random.sample(CHARACTERS, 15))

print(generate_unique_key())




You can also use the secrets library (thanks @MathiasEttinger) which is a CSRNG version of random. It also contains the function secrets.token_urlsafe (thanks @Graipher) which generates a random string which is safe for use in URLs. Allowing:

def generate_unique_key(size=15):
    return secrets.token_urlsafe(size)[:size]