The code and any(c in spec for c in password)
does in fact work. After PyxlDavon pointed out that my code does work, I closed and restarted my python interpreter and the code did work. So my only conclusion is that my python interpreter became unstable for some unkown reason. I haven’t seen this code style in any other related questions. I apologize for answering my own question. I got the idea for this code from this link: https://www.codespeedy.com/detect-if-a-string-contains-special-characters-or-not-in-python/#:~:text=To%20check%20if%20a%20string,special%20characters%20from%20the%20string.
1
solved Check for special characters in Python while loop [closed]