Skip to main content
 首页 » 编程设计

python之为什么我在两种方式之间得到长度差异 : dict and array

2025年05月04日13webabcd

哈希 是一个生成器。

  mapper = {} 
  for hash, offset in hashes: 
      mapper[hash.upper()] = offset 
  len(mapper) 

映射器的长度:1444

hashlist = [] 
for hash in hashes: 
    hashlist.append(hash) 
len(hashlist) 

哈希表长度:1477


这就是我不明白的!

请您参考如下方法:

很明显,当大写时你有重复的散列。字典中的键是唯一的,使用相同的(大写的)散列作为字典中的键将替换该键的先前值。

在你的例子中,你有 33 个散列,当大写时,之前已经出现过。