1
I have been playing with python, Dict and list compreensions. 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 compreension). that the output beyond that was:
{'Singapore dollar': {'value': '0.3653', 'code': 'SGD_NOON'}, 'Croatian kuna': {'value': '0.3653', 'code': 'HRK_NOON'}, ...
I tried to:
results = {i: {'value':dictLines[i][-1], 'code':dictLines[i][0] for i in dictLines} for i in dictLines}
But to no avail