today I would like to embed shipping price table to python dictionary and I have not idea how to start.
What I have?
I have table with shipping costs and zones.
+-----------+------+---------+--------+
| weight | Asia | America | Europe |
+-----------+------+---------+--------+
| 0-500 | 10 | 15 | 5 |
| 501-1000 | 13 | 18 | 8 |
| 1001-2000 | 16 | 21 | 11 |
+-----------+------+---------+--------+
What I have tried?
shipping_costs = [
{
"min_w": 0,
"max_w": 500,
"asia": 10,
"america": 15,
"europe": 5
},
{
"min_w": 501,
"max_w": 1000,
"asia": 13,
"america": 18,
"europe": 8
},
{
"min_w": 1001,
"max_w": 2000,
"asia": 16,
"america": 21,
"europe": 11
}
]
product_weight = 600
for zone in shipping_costs:
if zone['min_w'] <= product_weight <= zone['max_w']:
print('Asia: {}, America: {}, Europe: {}'.format(zone['asia'],zone['america'],zone['europe']))
And... And it works but I have doubts about search method. Is it properly way? Or is better tool to finding ranges?