gpt4 book ai didi

python - python 中 range() 的替代函数

转载 作者:行者123 更新时间:2023-12-01 02:06:27 25 4
gpt4 key购买 nike

我想遍历一个文本文件并打印 unicode 的出现。我想要一个合适的函数来代替范围。

  counter = {}
x={'0x0985':1,'0x0986':2,'0x0987':3,'0x0988':4,'0x0989':5}
for key,value in x.items():
x[key]=0
with open('bengali.txt', 'r', encoding='utf-8') as infile:
for line in infile:
for char in line:
n = ord(char)
if n in range{0x0985,0x0986,0x0987,0x0988,0x0989}
counter[n] += 1
for key, value in counter.items():
print(chr(key), value)

最佳答案

我根本不明白你为什么要在这里使用范围。

if n in (0x0985,0x0986,0x0987,0x0988,0x0989):

关于python - python 中 range() 的替代函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49009656/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com