有这种字典
{'telegram': {'afghanistan': {'virtual18': {'cost': 12.19, 'count': 1000}, 'virtual23': {'cost': 16.25, 'count': 1000}}
我需要按最低价格对价格值进行排序
import json
import requests
product = 'telegram'
headers = {
'Content-Type': 'application/json',
}
params = (
('product', product),
)
response = requests.get('https://5sim.net/v1/guest/prices', headers=headers, params=params)
r = response.json()
for smth in r['telegram']:
if smth['cost']:
print(smth)
然后我不明白如何遍历字典或者使用 min() 函数,帮我弄清楚
嗯,像这样:
结论:
尽管它们似乎在那里分类。但我只是向您展示了如何将其全部整理出来以及如何整理。您的任务没有明确定义。
如果您需要找到每个国家/地区的最低关税,然后按最低关税对更多国家/地区进行排序,那么您可以这样做:
结论: