来自用户输入的笛卡尔积 - 获取字符串而不是列表

问题描述

我正在处理一项任务,并且部分在那里,但坚持如何将输出作为单个列表与字符串。显然,我正在学习,非常感谢您提供的帮助或建议!

这是评估: 计算他们的笛卡尔积,两个列表的 AxB。每个列表的数字不超过 10 个。

例如,如果用户提供两个输入列表: A = [1,2] B = [3,4]

那么笛卡尔积输出应该是: AxB = [(1,3),(1,4),(2,4)]

这是我目前所写的内容:

import itertools

input_A = []
input_B = []

input_A = input('Enter first 2 - 10 characters: ')
input_B = input('Enter second 2 - 10 characters: ')

for combination in itertools.product(input_A,input_B):
  print('AxB = ',[combination])

这是我的输出:

Enter first 2 - 10 characters: 12 #I don't get the the below output when using comma separated items
Enter second 2 - 10 characters: 34
AxB =  [('1','3')]
AxB =  [('1','4')]
AxB =  [('2','3')]
AxB =  [('2','4')]

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)