【Python】一行代码求字符串笛卡尔积

版权声明:转载请说明出处,谢谢 https://blog.csdn.net/Asher117/article/details/89225847
>>>import itertools
>>>m = 'ab'
>>>n = 'cd'
>#求m和n的笛卡尔积
>>>data = itertools.product(m,n)
>>>[x for x in data]
>[('a', 'c'), ('a', 'd'), ('b', 'c'), ('b', 'd')]
>#求m自身笛卡尔积
>>>data = itertools.product(m,m)
>>>[x for x in data]
>[('a', 'a'), ('a', 'b'), ('b', 'a'), ('b', 'b')]

猜你喜欢

转载自blog.csdn.net/Asher117/article/details/89225847
今日推荐