函数 criarB 返回:
{269476: 200129, 209624: 200129 ...}
200129 position in aux2, '200129 and 209624 are keys'
如何根据键拆分dict,如果keys % 10 = 0 必须存储在list[0]中
list = [[], [], ...]
类完成:
class Buckets:
def __init__(self, keys, palavras, tamanhoP):
self.listaBuckts = dict()
self.listaHash = list()
self.keys = list(keys)
aux = list(zip(keys, palavras))
self.aux2 = list()
for i in range(0, len(aux), tamanhoP):
self.aux2.append(dict(aux[i:i + tamanhoP]))
def criarB(self):
for i, pag in enumerate(self.aux2):
for v in pag.keys():
self.listaBuckts[v] = i
return self.listaBuckts
def indexar(self):
count = 0
buckets = [[] for _ in range(10)]
for r in range(0, len(buckets)):
for s in range(0, len(self.listaBuckts)):
if s % 3 == 0:
buckets[r].append([v + count for v in self.listaHash[s:s + 3]])
count += 1
return buckets[0]
“索引”功能使用一个只包含索引的列表,如何使用 self.buckets 字典的键并根据功能划分字典
试图:
class Buckets:
def __init__(self, keys, palavras, tamanhoP):
self.listaBuckts = dict()
self.listaHash = list()
self.keys = list(keys)
aux = list(zip(keys, palavras))
self.aux2 = list()
for i in range(0, len(aux), tamanhoP):
self.aux2.append(dict(aux[i:i + tamanhoP]))
def criarB(self):
for i, pag in enumerate(self.aux2):
for v in pag.keys():
self.listaBuckts[v] = i
return self.listaBuckts
def indexar(self):
test = [[] for _ in range(10)]
for x in self.listaBuckts:
i = x % 10
test[i].append([x, dict[x]])
return test[0]
GCT1015
繁华开满天机
相关分类