7

深入JavaScript高级语法-coderwhy

 2 years ago
source link: https://segmentfault.com/a/1190000041016995
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

download:深入JavaScript高级语法-coderwhy

set()函数创立一个无序不反复元素集,可停止关系测试,删除反复数据,还能够计算交集、差集、并集等。

set 语法:

class set([iterable])

参数阐明:

iterable -- 可迭代对象对象;

返回新的汇合对象。

将列表转为汇合:

扩展举例:

python将3X4的矩阵列表转换为4X3列表

matrix = [
[1, 2, 3, 4],
[5, 6, 7, 8],
[9, 10, 11, 12],
]

for x in range(len(matrix)):

print (matrix[x])

hehe = [[row[i] for row in matrix] for i in range(4)]
print (hehe)

one = []
for x in range(4):

one.append([row[x] for row in matrix])
pass

print (one)

three = []
for x in range(4):

two = []
for i in matrix:
    two.append(i[x])
    pass
three.append(two)
pass

print (three)
以上就是本次关于python怎样把转列表为汇合的细致内容,感激大家的学习和对脚本之家的支持


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK