On Wed, May 25, 2011 at 6:25 PM, Wolf Halton <wolf.hal...@gmail.com> wrote: > Is there a less clunky way to do this? > [code] > def new_pass(): > series = ['`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', > '=', \ > '~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', > '+', \ > 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', > '\\', \ > 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}', > '|', \ > 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', "'", \ > 'A', 'S', 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', \ > 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', \ > 'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?'] > passwd = [] > p = input("Enter the length you want your password to be: ") > # length of password > for i in range(p): > r = random.randint(0, 94) > passwd.append(series[r]) # Append a random char from series[] to > passwd > #print passwd > #print passwd[0], passwd[1], passwd[2], passwd[3] > print "" > print "".join(map(str, passwd)), " is your new password. \n" > [/code]
I suggest you read up on the random module - there's two things that you'll find immediately useful - random.choice and random.sample. I suggest you use sample instead of the for loop you're using. Also, when you print the output, there's no need to use map - everything in your series. _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor