0

Example i have 2 lists.

import string
character1= list(string.punctuation)
password=['a','b','1','@']
if(character1 in password):
    print("Error! Because you have a special character/characters in your password.Try again")
else:
    pass

How can i create a program like this? It isn't work in jupyter. Thanks for helping!

1 Answers1

1

Currently, character1 in your code is a list and you are testing to see if this list is in the password list. You need to test whether there exists an element in character1 that is in password. One way to do this is to use the any() Python built-in function (documentation). any() accepts as an argument an iterable (in your case, a list) and "returns True if any element of the iterable is true". Below, this iterable argument is the generator (i for password for i in character1).

if any(i in password for i in character1):
    print("Error! Because you have a special character/characters in your password.Try again")
else:
    pass
OTheDev
  • 2,916
  • 2
  • 4
  • 20