Answer the question
In order to leave comments, you need to log in
How to add an element to the list so that it does not repeat several times?
I'm writing a small password guessing program. The for loop checks for a password in the used_password_list and adds it if it's not there. Only there is one catch: the password is added as many times as in the list of elements, how to fix this? Can you use some alternative?
while y < 10:
password_call = random_password()
for i in used_password_list:
if i != password_call:
used_password_list.append(password_call)
print (password_call)
Answer the question
In order to leave comments, you need to log in
Can you use some alternative?
https://docs.python.org/2/library/sets.html
There is another option:
book.pythontips.com/en/latest/for_-_else.html
while y < 10:
password_call = random_password()
for i in used_password_list:
if i == password_call:
break
else:
used_password_list.append(password_call)
print (password_call)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question