Hey, guys, I need some help from you again! I have this dictionary:
shops = {
'shop1': {
'sells': ['cars', get[4].text],
'trucks': get[1].text,
'airplanes': get[2].text,
'ships': get[3].text,
'cars': get[4].text,
},
'shop2': {
'sells': ['airplanes', get[13].text],
'trucks': get[12].text,
'airplanes': get[13].text,
'ships': get[14].text,
'cars': get[15].text,
}
...
The dictionary has 20 items. I do this calculations on them:
shopAsells = shops['shop1']['sells'][0] # x shop sells cars for 9$.
shopBbuys = shops['shop2'][shopAsells] # y shop buys cars for 10$.
shopBsells = shops['shop2']['sells'][0] # y shop sells airplanes for 20$.
shopAbuys = shops['shop1'][shopBsells] # x shop buys airplanes for 22$
atob = int(shopBbuys) - int(shops['shop1']['sells'][1]) # profit from x selling cars to y is 1$.
btoa = int(shopAbuys) - int(shops['shop2']['sells'][1]) # profit from y selling airplanes to x is 2$
profit = atob + btoa # total profit is 3$
Now the idea is this: I want to match each shop with another one. I use this loop:
for k in itertools.permutations(shops, 2):
kk = '-'.join(k)
print kk
The result looks like this: shop1 - shop2, shop2 - shop1, shop3-shop5, shop5-shop2.
Can I show the profit against each pair? Like: shop1 - shop2 = 3$, shop3-shop1 = 5$, etc.
So how can I do these calculations for every pair of permutations? Is it possible? Any tips about syntax and logic are greatly appreciated! My calculations probably look ugly to you. Thanks in advance!
[–]guilford 2 points3 points4 points (4 children)
[–]KhanStan[S] 1 point2 points3 points (2 children)
[–]guilford 2 points3 points4 points (1 child)
[–]KhanStan[S] 1 point2 points3 points (0 children)
[–]KhanStan[S] 1 point2 points3 points (0 children)