def cartesian_product(table1, table2):
'''(table, table) -> table
Return a table that is created by joining the tables table1 and table2. The
cartesian products of the two tables is a new table where each row in the first
table is paired with every row in the second table. Each table is supposed to
be a dictionary.
Example:
dict1 = {'a': ['b', 'c']}
dict2 = {'d': ['e', 'f']}
cartesian_product({'a': ['b', 'c']}, {'d': ['e', 'f']})
{'a': ['b', 'b', 'c', 'c'], 'd': ['e', 'f', 'e', 'f']}
'''
table1 = list(table1.values())
table2 = list(table2.values())
for object1 in table1:
x = object1
for object2 in table2:
y = object2
return x,y
這是我到目前爲止,我知道的輸出是:你如何製作價值對並重復它們?
(['b', 'c'], ['e', 'f'])
我想它返回:
{'a': ['b', 'b', 'c', 'c'], 'd': ['e', 'f', 'e', 'f']}
我可以嘗試返回字典自己 - 但在列表中 - 你如何配對並重復它們?
爲什麼是'[ 'E',「F ','e','f']和'['a','a','b','b']'。我沒有看到這裏的模式... – mgilson
啊,我想我現在看到它;它應該是一個兩行的表格; 'b'和'e'是一對,所以是'b'和'f',然後'c'和'e'以及'c'和'f'等。 –
哈哈...太棒了...我...有這個昨天的答案...和OP刪除他們的問題...現在我找不到保存的副本:) –