Is there a way to generate special chars in python . | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

Is there a way to generate special chars in python .

There must be an easy way to generate these characters, can someone help me ? Password Validation ALPHABETS = [ 'A','B','C','D','E','F','G','H','I','','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z', ] SPECIAL_CHARS = [ '!', '@', '#', '

#x27;, '%', '&', '*', ] NUMBERS = [ '1', '2', '3', '4', '5', '6', '7','8','9','0', ] def checker(pwd): letters = [] chars = [] num = [] for char in pwd: if char in ALPHABETS: letters.append(char) if char in NUMBERS: num.append(char) if char in SPECIAL_CHARS: chars.append(char) if len(pwd) >= 7 and len(chars) >= 2 and len(num) >= 2: return "Strong" else: return "Weak" print (checker (input()))

15th Apr 2021, 12:48 AM
Dev_Govi
Dev_Govi - avatar
4 Answers
+ 1
No worries, I added an index slice, it should help with isolating the data you want, but you can also change the range function too
15th Apr 2021, 1:09 AM
Steven M
Steven M - avatar
15th Apr 2021, 1:00 AM
Steven M
Steven M - avatar
+ 2
Thanks
15th Apr 2021, 1:04 AM
Dev_Govi
Dev_Govi - avatar
+ 2
There are built-in string constants that can be used for many groups of character types. https://docs.python.org/3/library/string.html
15th Apr 2021, 1:41 AM
ChaoticDawg
ChaoticDawg - avatar