zip is a general method of functional programming, such as map or fold. You will find these functions in early methods before ruby ββand python. They are designed to perform general batch operations in lists.
In this particular case, zip takes two lists and creates a new list of tuples from these lists.
for example, let's say you have a list with (1,2,3), and the other with ("one", "two", "three") If you fasten them together, you will get List ((1, "one") , (2, two), (3, three))
or from the scala command line, you will get:
scala> List(1,2,3).zip(List("one","two","three")) res2: List[(Int, java.lang.String)] = List((1,one), (2,two), (3,three))
When I first saw it in Python, not knowing functional programming, I thought it was related to the compression format. After I learned more about functional programming, I used it more and more.
drudru Jul 12 '09 at 8:34 2009-07-12 08:34
source share