def check_keyboard_coiled_input(target_str):# 万能保险罩try:t_str = target_str.lower()# row 行坐标row = []# col 列坐标col = []# 全都转小写char_list_no_shift = [['`', '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=', None],[None, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']', '\\'],[None, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', '\'', None, None],[None, 'z', 'x', 'c', 'v', 'b', 'n', 'm', ',', '.', '/', None, None, None]]char_list_shift = [['~', '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+', None],[None, 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '{', '}', '|'],[None, 'a', 's', 'd', 'f', 'g', 'h', 'j', 'k', 'l', ':', '"', None, None],[None, 'z', 'x', 'c', 'v', 'b', 'n', 'm', '<', '>', '?', None, None, None],]for t in range(len(t_str)):for clnt_idx, clnt in enumerate(char_list_no_shift):for i_idx, i in enumerate(clnt):if t_str[t] == i:row.insert(t, clnt_idx)col.insert(t, i_idx)# 表示第一组找到了if len(row) > t: continuefor clt_idx, clt in enumerate(char_list_shift):for j_idx, j in enumerate(clt):if t_str[t] == j:row.insert(t, clt_idx)col.insert(t, j_idx)# 连续三个for x in range(1, len(t_str) - 1):# 判断是不是在一行if row[x - 1] == row[x] and row[x] == row[x + 1]:if (col[x - 1] + 1 == col[x] and col[x] + 1 == col[x + 1]) or \(col[x + 1] + 1 == col[x] and col[x] + 1 == col[x - 1]):t_set = set()t_set.add("".join([char_list_no_shift[row[x - 1]][col[x - 1]],char_list_no_shift[row[x]][col[x]],char_list_no_shift[row[x + 1]][col[x + 1]]]))t_set.add("".join([char_list_shift[row[x - 1]][col[x - 1]],char_list_shift[row[x]][col[x]],char_list_shift[row[x + 1]][col[x + 1]]]))return {"res": True, "keyword": " or ".join(list(t_set))}elif col[x - 1] == col[x] and col[x] == col[x + 1]:if (row[x - 1] + 1 == row[x] and row[x] + 1 == row[x + 1]) or \(row[x + 1] + 1 == row[x] and row[x] + 1 == row[x - 1]):t_set = set()t_set.add("".join([char_list_no_shift[row[x - 1]][col[x - 1]],char_list_no_shift[row[x]][col[x]],char_list_no_shift[row[x + 1]][col[x + 1]]]))t_set.add("".join([char_list_shift[row[x - 1]][col[x - 1]],char_list_shift[row[x]][col[x]],char_list_shift[row[x + 1]][col[x + 1]]]))return {"res": True, "keyword": " or ".join(list(t_set))}except:passreturn {"res": False}

参考链接: https://blog.csdn.net/sjdjjd6466446/article/details/108991554

判断字符串是否存在3个连续的键盘按键相关推荐

  1. C++判断字符串中是否有中文

    参考: http://baike.baidu.com/view/391899.htm?fr=aladdin http://baike.baidu.com/view/1204863.htm http:/ ...

  2. java判断字符串是否包含某个字符串_Bash技巧:使用[[命令的 =~ 操作符判断字符串的包含关系...

    在 Linux bash shell 中,可以使用 [[ 命令来进行判断. 其中,可以使用 [[ 命令的 =- 操作符来判断某个字符串是否包含特定模式. 查看 man bash 对 [[ 命令的 =~ ...

  3. oracle 判断数字是否连续,oracle中 如何 判断 表中字段是否为 连续的数字,例如‘3333333333',‘44444444’...

    oracle中 如何 判断 表中字段是否为 连续的数字,例如'3333333333','44444444' (2011-09-23 15:42:45) 标签: 判断 字段是否为 连续的数字 杂谈 分类 ...

  4. LeetCode——1849. 将字符串拆分为递减的连续值(Splitting a String Into Descending Consecutive Val..)[中等]——分析及代码(Java)

    LeetCode--1849. 将字符串拆分为递减的连续值[Splitting a String Into Descending Consecutive Values][中等]--分析及代码[Java ...

  5. js判断字符串处于键盘三连键

    前言 有个弱密码的需求,需要判断用户注册的密码不能是键盘三连键的,比如说(123,qaz,rew,TRE,%RD,bhu)等等,找了下都没有最完美解决方案,故而自己基于网上的方案进一步封装了下. 解决 ...

  6. java判断字符串是否为数字的几种方式

    一,使用StringUtils工具类: 通过StringUilts工具包进行判断: org.apache.commons.lang3.StringUtils提供了丰富的字符串解析的工具包,其中isNu ...

  7. C++ 判断字符串是否为空

    C++ 判断字符串是否为空 有2种方法 1种是用使用empty 2 使用== 与"" 比较 具体的如下: #include <iostream> #include &l ...

  8. 判断字符串不包含某个字符php,java判断字符串是否包含某个字符的方法

    java判断字符串是否包含某个字符的方法: 一.contains方法 1:描述 java.lang.String.contains() 方法返回true,当且仅当此字符串包含指定的char值序列 2: ...

  9. python 判断字符串是否包含另一个字符串_强烈推荐:Python字符串(string)方法整理(一)...

    作者:骏马金龙 原文地址: https://www.cnblogs.com/f-ck-need-u/p/9127699.html python中字符串对象提供了很多方法来操作字符串,功能相当丰富. p ...

最新文章

  1. 微信小程序导航栏设置透明
  2. MySQL对查询结果排序
  3. python numpy np.lexsort()(使用键序列执行间接稳定排序)(具体没太搞懂区别?)
  4. Java 策略模式和状态模式
  5. 《明日方舟》的塔防元素:是鸡肋还是精髓?
  6. jsp输入限制正则表达式
  7. lintcode-514-栅栏染色
  8. linux u盘分区 mdev 卸载问题,嵌入式linux 实现mdev SD卡和U盘自动挂载和卸载的方法 mdev.conf...
  9. 2019.04.09 电商25 结算功能1
  10. CLion导入用户自己的lib和头文件
  11. Java UDP 客户端服务器程序示例
  12. Mac 修改hosts文件
  13. ps怎么放大图片保持清晰度?
  14. 激光粒度仪测试原理及详情解答【注解】
  15. 【ENVI条件下的GF6-WFV数据处理相关问题】——负值问题
  16. [week13] 2 - T1
  17. 2021海南安全员考试及(安全员)模拟考试答案解析
  18. App Store上推广App的实战经验
  19. Xmind8 (update8)破解教程
  20. 【微信小程序】父子组件之间传值

热门文章

  1. 使用Microsoft Hyperspace索引Spark数据
  2. 使用parted工具 创建GPT分区,并进行扩容
  3. 迅雷/旋风地址转换原理分析(转)
  4. 深度学习中的FLOPs是什么?如何计算的?
  5. html实现鼠标跟随,js实现鼠标跟随运动效果
  6. 何去何从,飞进寒冬的无人机
  7. 基于GPS北斗卫星授时系统和NTP网络授时服务器的设计与开发
  8. 【动画宣传片视频制作软件】Focusky教程 | 添加*flv或*.mp4视频背景
  9. 票务app开发案例分享
  10. emwin 5.5下载