What is the purpose of a zip function (as in Python or C# 4.0)?

后端 未结 7 2224
北荒
北荒 2020-12-29 09:27

Someone asked How to do Python’s zip in C#?...

...which leads me to ask, what good is zip? In what scenarios do I need this? Is it really so foundational that I n

7条回答
  •  既然无缘
    2020-12-29 09:54

    Here's a common use case for zip:

    x = [1,2,3,4,5]
    y = [6,7,8,9,0]
    
    for a,b in zip(x,y):
        print a, b
    

    Which would output:

    1 6
    2 7
    3 8
    4 9
    5 0
    

提交回复
热议问题