Problem in class dict and joining large amount of elements per dict in Python

0

Hello, I'm having problems with dict . I have two lists: lista1 and lista2 , both of the same size. When I run the command: dicionario = dict(zip(lista1, lista2)) produces a dictionary "smaller" than the size of the list. I've done a lot of testing and that's what's really going on. In each loop I made a print of the size of lista1 and lista2 and they always have the same size. I have separated the operations of zip and dict and always made print of both. Result: dict is not concatenating correctly. Remember that the keys for my dict are double and the values are lists of lists (that is, lista1 = 52.84 and lista2 = [[1, 2, 3],[1, 2, 4],[5, 6, 7]] for example). The fact that it is a large amount of data can influence? In this case each list has 100 positions, as I said. The lista1 is a list of 100 positions consisting of double values and lista2 is a list of lists ( lista2 = [list1, list2, list3, ..., list_100] ) that has 100 positions and each [list1, list2, list3, ..., list_100] element. It's 80. Can I explain? Help haha urgently

    
asked by anonymous 17.07.2016 / 08:08

1 answer

0

Allan,

According to zip documentation:

  

The iterator stops when the shortest iterable input is exhausted.

So there must be some error in validating your data that you can not identify that one of the lists is smaller than the other. As for the size of the data, I've replicated your problem using 100 times larger lists to show that there are no problems.

# Criamos a lista de floats com 10000 posições
lista1 = list(np.random.random_sample(10000))
print(len(lista1) == 10000)
True

# Segunda lista de 10000 listas com 8000 posições cada.
lista2 = [[' '] * 8000 for x in range(0, 10000)]
print(len(lista2) == 10000)
True
print(all([len(x) == 8000 for x in lista2]) == True)
True

# Geramos o dicionário
dicionario = dict(zip(lista1, lista2))
print(len(dicionario) == 10000)
True

# Validamos os dados
print(all([len(y) == 8000 for x, y in dicionario.items()]))
True

In this way we validate the obtaining of a dictionary with 10000 keys, each corresponding to a list of 8000 positions.

    
19.01.2017 / 19:42