Python 实现笛卡尔积

# 代码备忘
x = ['a', 'b', 'c']  
y = ['1', '2', '3']

c = [[a, b] for a in x for b in y]

# c = [('a','1'), ('a','2'), ('a','3'),
#      ('b','1'), ('b','2'), ('b','3'),
#      ('c','1'), ('c','2'), ('c','3')]

Friskit

继续阅读此作者的更多文章