Zip function giving incorrect output

I am writing a cryptographic algorithm using Python, but I have never worked with Python before.

First of all, look at this code, then I will explain the problem,

x = bytearray(salt[16:]) y = bytearray(sha_512[32:48]) c = [ i ^ j for i, j in zip( x, y ) ] 

X and y are equal,

 bytearray(b'AB\xc8s\x0eYzr2n\xe7\x06\x93\x07\xe2;') bytearray(b'+q\xd4oR\x94q\xf7\x81vN\xfcz/\xa5\x8b') 

I could not understand the third line of code. To understand the third line, I had to study the zip() function, I came across this question,

Zip function help with tuples

In response to this question, code,

 zip((1,2,3),(10,20,30),(100,200,300)) 

will output

 [(1, 10, 100), (2, 20, 200), (3, 30, 300)] 

but when I try to print it,

 print(zip((1,2,3),(10,20,30),(100,200,300))) 

I get this conclusion,

 <zip object at 0x0000000001C86108> 

Why is my conclusion different from the original?

+7
python
source share
1 answer

In Python 3, the zip returns an iterator , use list to see its contents:

 >>> list(zip((1,2,3),(10,20,30),(100,200,300))) [(1, 10, 100), (2, 20, 200), (3, 30, 300)] 

c = [ i ^ j for i, j in zip( x, y ) ] is a concept in which you repeat the elements returned from zip and perform some operations on them to create a new list.

+14
source share

All Articles