中文分词-逆向最大匹配法 “SyntaxWarning: “is“ with a literal. Did you mean “==“?”

def cutB(sentence,dictB):
    result = []
    sentenceLen = len(sentence)
    maxDictB = max([len(word) for word in dictB])
    while sentenceLen > 0:
        word = ''
        for i in range(maxDictB, 0, -1):
            piece = sentence[sentenceLen - i:sentenceLen]
            if piece in dictB:
                word = piece
                result.append(word)
                sentenceLen -= i
                break
        if word is '':
            sentenceLen -= 1
            result.append(sentence[sentenceLen])

    print(result[::-1],end="")

<>:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
<>:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
C:\Users\41588\AppData\Local\Temp\ipykernel_4896\1394694574.py:14: SyntaxWarning: “is” with a literal. Did you mean “==”?
if word is ”:

Python错误“SyntaxWarning: “is“ with a literal. Did you mean “==“?”

Python 3.8(或更高)下:
出现报错:

SyntaxWarning: “is” with a literal. Did you mean “==”?

解决方法:
将对应语句中is/is not用== 和 != 代替

原因:从 python 3.8 开始,使用 is 和 is not 运算符时,会抛出 SyntaxWarning 语句警告信息

125jz网原创文章。发布者:江山如画,转载请注明出处:http://www.125jz.com/12274.html

(0)
江山如画的头像江山如画管理团队
上一篇 2023年10月3日 上午8:49
下一篇 2023年10月3日 上午10:53

99%的人还看了以下文章

  • Pycharm Django项目 NameError: name ‘os’ is not defined

    Pycharm Djarngo项目报错 NameError: name ‘os’ is not defined 原因:这里调用了os模块,但是文件头并没引用os模块解决办法:在settings.py文件头加上 import os

    2024年12月2日
    2740
  • 详解如何在myeclipse中运行JSP,Run As none applicable(图)

    在MyEclipse中打开JAVA Project时想运行单个JAVA文件,如Hello.java文件,可以在Hello.java右键Run As 后面出现java Application,点击即可运行。 在myEclipse中打开web project,想运行单个JSP文件或项目,在jsp文件上右键Run As 没有”run on server…

    2020年2月23日
    12.2K0
  • Myeclipse设置JSP视图和代码显示在同一个窗口

    Myeclipse开发时,想同时查看页面及代码视图,如上图,而默认只能看到代码。 Myeclipse设置JSP页面和代码显示在同一个窗口的方法有两种。 一、在JSP页面上右击-open with-other… 在弹出的Editor selection窗口中选择web page editor,就可以了。 二、选择 window-preferences,如下图,…

    2018年12月17日 编程开发
    3.8K0
  • OpenCV-最优秀的Python人脸识别库安装及入门教程

    OpenCV库(open source computer vision library)是一个基于BSD许可(开源)发行的跨平台计算机视觉和机器学习软件库,可以运行在Linux、Windows、Android和Mac OS操作系统上,具有跨平台特性,轻量级且高效,实现了图像处理和计算机视觉方面的很多通用算法。 OpenCV用C++语言编写,它具有C ++,P…

    2020年12月8日
    5.7K2
  • Python编程入门:英文词频统计

    text = “Got tho on super sale. Love it! Cuts my drying time in half Reckon I have had this about a year now,\ at least 7 months. Works great, I use it 5 days a week, blows hot air,…

    2023年10月3日
    4.9K0
  • 纯JSP实现计算圆的面积和周长

    一个jsp页面由元素和模板数据组成.元素是必须由jsp容器处理的部分.而模板数据是jsp容器不处理的部分,如jsp中的HTML内容 元素有三种类型: 脚本元素,指令元素, 动作元素 脚本元素:包含三个部分:声明,脚本段,表达式 声明:用于声明在其它脚本元素中可以使用的变量和方法 脚本段:是一段java代码 表达式:java语言中完整的表达式 声明 以<…

    2020年4月3日
    10.0K0

发表回复

登录后才能评论