这是我第一次提出问题,而且我不是编程专家,所以对我好点。:)
我目前在 phyton 中使用一个外部代码,它永久地为我提供当前的比特币价格。不幸的是,此功能不仅提供价格,而且还使用所选货币填充列表。但我只想要一个带有数值的列表。
以下是条目列表的格式:
[{'BTC': {'EUR': 28843.76}}]
希望任何人都可以帮助我!
这是我第一次提出问题,而且我不是编程专家,所以对我好点。:)
我目前在 phyton 中使用一个外部代码,它永久地为我提供当前的比特币价格。不幸的是,此功能不仅提供价格,而且还使用所选货币填充列表。但我只想要一个带有数值的列表。
以下是条目列表的格式:
[{'BTC': {'EUR': 28843.76}}]
希望任何人都可以帮助我!
The output is in the form of a dictionary in a list. So what you can do is get the value ('EUR':28843.76) from the key ('BTC').
We can do that using the get() function:
input = [{'BTC': {'EUR': 28843.76}}] #Initializing the list.
for i in input: # Just going to iterate through the list
firstset = i.get('BTC') # Gives firstset the value of {'EUR':28843.76}
Now we have the above value. As it is another dictionary, we can use get() again:
value = firstset.get('EUR')
Now value contains the numerical i.e. 28843.76
Read this to learn about dictionaries - enter link description here