Python小技巧:使用*解包和itertools.product()求笛卡尔积

【问题】 目前有一字符串s = "['a', 'b'],['c', 'd']",想把它分开成为两个列表: list1 = ['a', 'b'] list2 = ['c', 'd'] 之后使用itertools.product()求笛卡尔积,应该写成: 1 for i in itertools.product(list1, list2): 2 print i 结果为: ('a', 'c')
相关文章
相关标签/搜索