Python 3 dicts and zip problem

Asked

Viewed 102 times

0

I’m having trouble with my job dict(zip(x, y)) when I pass as parameter the two lists (x and y) the zip does not create the list of the original size, randomly creates the list in the original size, but mostly always between 2 to 5 values less. This to suppose for x which has size 100 and y also size 100. Both x and y is the same size. How do I fix it? Thank you very much!

  • 2

    simply one of your lists at some point is less than the other is the only explanation for this to happen...

  • yes, I thought that too, but if I tell you it seems unbelievable, I asked to print the size of x and of y for len(x) and len(y). I had the operation zip separately and stored in one variable: var_exemplo = zip(x, y). I printed the list size: len(var_exemplo). So far so good. But after I did Dict separately, it generated a Dict with fewer indexes than normal: novo_dict = dict(var_exemplo). What do you suggest? PS: I did it many and many times before posting here, to be sure and that’s right.

  • just one touch stop duplicating questions, you asked that question and hours later repeated the same question calm down the community will help you ....

1 answer

0

Your list "x" is used as a key for dictionaries: the keys of dictionaries are unique - any repeated value of x there goes over-write the previously stored key/value pair.

What is happening is that you have some repeated values in your list x.

As you said no more walks on the nature of your data, and expected output is only as far as it is possible to answer.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.