I've been playing around with python, dict and list comprehensions. I made this little script:
import requests
url = 'http://www.bankofcanada.ca/en/markets/csv/exchange_eng.csv'
resp = requests.get(url)
page = resp.text
lines = [line for line in page.split('\n') if not line.startswith('#') and line != '' and not line.startswith('Date')]
dictLines = {line.split(', ')[0]: line.split(', ')[1:] for line in lines}
print(dictLines)
print('\n\n\n\n')
results = {i: {'value':dictLines[i][-1] for i in dictLines} for i in dictLines}
print(results)
Output:
{'Singapore dollar': {'value': '0.3653'}, 'Croatian kuna': {'value': '0.3653'}, ...
What I liked, and if possible, is that using this same technique (dict and list understanding). that the output in addition would be:
{'Singapore dollar': {'value': '0.3653', 'code': 'SGD_NOON'}, 'Croatian kuna': {'value': '0.3653', 'code': 'HRK_NOON'}, ...
I tried:
results = {i: {'value':dictLines[i][-1], 'code':dictLines[i][0] for i in dictLines} for i in dictLines}
But unsuccessful