Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图理解这一点:
a = "hello" b = "world" [chr(ord(x) ^ ord(y)) for (x, y) in zip(a[:len(b)], b)]
我理解这XOR部分,但我不明白 zip 在做什么。
XOR
zip将a和的每个字母组合b在一起。
zip
a
b
a = "hello" b = "world" print zip(a, b) >>> [('h', 'w'), ('e', 'o'), ('l', 'r'), ('l', 'l'), ('o', 'd')]
它并没有为zip做任何不寻常的事情。
由于假定了这种行为,因此列表切片a是多余的。zip
如文档中所述:
此函数返回一个元组列表,其中第 i 个元组包含来自每个参数序列或可迭代对象的第 i 个元素。