我已经编写了一个网页爬虫程序,它将货币交换值作为嵌套列表返回,并且我试图编写代码的一部分来搜索给定名称并通过此列表提取货币与之相关的价值数据。在列表/字典错误内搜索
我的记录功能,看起来像
[['Argentine Peso', ['9.44195', '0.10591']], ['Australian Dollar', ['1.41824', '0.70510']]
和功能应该是能够搜索,如“阿根廷比索”的货币名称,并返回
[9.44195,0.10591]
如何将我去有关?
def findCurrencyValue(records, currency_name):
l = [[(records)]]
d = dict(l)
d[currency_name]
return(d)
def main():
url = "https://www.cs.purdue.edu/homes/jind/exchangerate.html"
records = fetch(url)
findCurrencyValue(records, "Argentine Peso")
print(findCurrencyValue)
print("currency exchange information is\n", records)
main()
,但我得到的错误
ValueError: dictionary update sequence element #0 has length 1; 2 is required
我回答到这里你的问题:http://stackoverflow.com/questions/33490506/list-dictionary-error-in-my-code/33490714#33490714你应该尝试一下。 –
即时通讯不允许使用外部程序 –