我有以下两个列表:
Sites = ["iTunes","Google"]
PurchaseTypes = ["Rental","Purchase"]
我如何将所有组合相乘,从而产生:
[
"iTunesRental",
"iTunesPurchase",
"GoogleRental",
"GooglePurchase"
]
是否有python操作可以做到这一点?或者是否需要为每个列表执行一个 for 循环?即:
combined = []
for s in sites:
for pt in purchase_types:
combined.append(s+pt)
请您参考如下方法:
使用列表理解:
>>> [a + b for a in Sites for b in PurchaseTypes]
['iTunesRental', 'iTunesPurchase', 'GoogleRental', 'GooglePurchase']
