python - 使用 not in 运算符打破 python 循环
问题描述
此循环未按预期工作。它打印所有 4 个元素(预计 3 个)
guj = ["बळींचाी", "आठ़वले", "मोठय़ा", "धाांची"]
for y in guj:
for i in y:
x = i.encode("raw_unicode_escape")
if x[:5][-3:] not in [b"090", b"091", b"092", b"093", b"094"]:
break
print(y)
不应打印第三个单词,因为它包含一个无效的 095 系列字符。
# "य़".encode("raw_unicode_escape") # b'\\u095f'
输出.txt
बळींचाी
आठ़वले
मोठय़ा
धाांची
预期的.txt
बळींचाी
आठ़वले
धाांची
解决方案
推荐阅读
- python - Pytorch Siamese NN 与 BERT 用于句子匹配
- java - 是否有从 Luwak 到新 Lucene 版本的迁移文件?
- c# - 如何在 foreach 循环 cc# 中读取 xml 子节点
- python - 计算较长时间段内几个月的平均值
- node.js - 在 nodejs 后端使用 msal 时出错
- javascript - 如何修复那些转换工作 JavaScript Svelte 3 商店的 Typescript-Eslint 警告?
- linux - 绝对值的 sh 脚本
- javascript - 打包js文件导入bpmn图时webpack失败
- couchbase - Couchbase 6.5.1 - cbtransfer - 将数据拆分为多个文件
- sql - 如何从 Azure SQL 托管实例中执行 Web 获取