python - 将字符串与列表中的元素进行比较

标签 python python-3.x string list comparison

我正在尝试编写一个密码强度检查器,如果输入的密码是常见的键盘组合(例如“qwerty”或“asdfg”),我想扣分。我有一个列表 ['q', 'w', 'e', ... 'b', 'n', 'm']。如果输入的任何部分具有列表中的连续元素,我想扣分。假设密码是“djoDFGibTY”(大写只是为了突出显示,全部小写),我希望我的代码捕获“DFG”和“TY”并扣分两次,在第一种情况下三次违规会扣更多分,在第二种情况下,双重违规的金额较小。谢谢。

keyboard_pattern = ['q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', 'z', 'x', 'c', 'v', 'b', 'n', 'm']

if password in keyboard_pattern:

score -= 15

最佳答案

https://codereview.stackexchange.com/questions/177415/python-qwerty-keyboard-checker 上所示

input = input("What is your password?")
qwerty = 'qwertyuiopasdfghjklzxcvbnm'
lower = input.lower()
for idx in range(0, len(lower) - 2):
    test_seq = lower[idx:idx + 3]
    if test_seq in qwerty:
        points -= 5
print(points)

关于python - 将字符串与列表中的元素进行比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56666614/

相关文章:

python-3.x - HTTP错误 : HTTP Error 403: urlib3 while using smopy

Python - 检查正在使用哪个子类

javascript - 正则表达式在Javascript中获取括号之间的字符串

python - pymc 对多个变量进行观察

c++ - 从 Python 扩展调用 C++ 虚拟成员时崩溃

Python: 'int' 对象在 map.Pool 中不可迭代

python - 属性错误 : 'list' object has no attribute 'copy'

python-3.x - Python 3 ~ 如何从 csv 文件中获取行并将它们放入列表中

ruby-on-rails - 在 Ruby on Rails 中测试字符串是否为数字

c - 奇怪的字符替换(对我来说)毫无意义