zip()
多个列表值转成一个多维的列表:
>> zip(1px 2px 3px,solid dashed dotted,green blue red)
((1px "solid" #008000), (2px "dashed" #0000ff), (3px "dotted" #ff0000))
在使用zip()函数时,每个单一的列表个数值必须是相同的:
>> zip(1px 2px 3px, solid , green blue red)
NoMethodError: undefined method `options=' for nil:NilClass
Use --trace for backtrace.
否则将会出错。
zip()函数中每个单一列表的值对应的取其相同位置值:
--- List --- | --- nth(1) --- | --- nth(2) --- | --- nth(3) --- |
---|---|---|---|
List1 | 1px | 2px | 3px |
------------ | -------------- | -------------- | -------------- |
List2 | solid | dashed | dotted |
------------ | -------------- | -------------- | -------------- |
List3 | green | blue | red |
------------ | -------------- | -------------- | -------------- |
zip()函数组合出来就成了:
1px solid green, 2px dashed blue, 3px dotted red