I am trying to make a random password generator based on three parameters. Number of letters, symbols, and numbers. I would like to use a list but when I print it the brackets, quotes, and commas show up. If I enter a pre-filled list eg. ["1", "g", "&", "0"]
, print (*password, sep='')
works as expected. Not when the list is randomly populated though. Is there another function I can use?
Do not mind the new_let
, new_num
, new_sym
in my for loops. Was just trying something out.
The problem in your example code is that password
is not a list of characters but a list of lists. Use random.choice()
instead of random.choices()
. The latter returns a list.
There is no reason for your solution not to work on a randomly generated list
import random
l=["1", "g", "&", "0",'d','2']
print(*[random.choice(l) for i in range(5)], sep='')
01dg2
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.