Home > other >  To help explain the
To help explain the

Time:11-09

>> The list (map (list, zip (* [[1, 2, 3], [4 and 6]])))
[[1, 4], [2, 5], [3, 6]]

CodePudding user response:

1. The zip inside (* [[1, 2, 3], [4 and 6]]) is equivalent to zip ([1, 2, 3], [4, 5, 6]), i.e., * a list of elements to be brought out
2. Zip () function is to put the two list for one by one, is the translation of zip zip, like clothes zipper put two sets of data to knead together
3. The map () is the first function (here is the list) role in the second parameter of each item, here is the zip combination of each object, the equivalent of [the list ([1, 4]), the list [2, 5], the list [3, 6]],
4. Use the map function form is map object, so the outside using a list () function converts the map object to list
Your code is equivalent to:
 a=[1, 2, 3] 
B=[4, 5, 6]
Result=[]
For I in range (len) (a) :
[I]=\ [a, b] [I]
Result. Append (temp)
Print (result)

CodePudding user response:

* is unbundling, that is to say * [[1, 2, 3], [4 and 6]] is equivalent to [1, 2, 3] [4, 5, 6]
Will zip () function is used to iterative object as a parameter, the object packaged into the corresponding element in each tuple, then returns the composed of these tuples
Map () according to the function of the offer of specified sequence map
So here the map function is zip list into a list of tuples in packaging, so the zip package (1, 4) and (2, 5) (3, 6) into a [1, 4] [3], [2, 5] finally use the list () transformation to output columns [[1, 4], [2, 5] [3]]
  • Related