-2

I am currently working on a task, where I should make trading decisions on the base of MA Crossovers.

I am thinking about an approach which involves a dictionary, however, I am still really inexperienced in how to create those.

My idea is to convert a list like following:

cross = [[2, 2], [3, 1], [6, 2], [9, 1], [12, 1]]

where: [time_index, buy_index]

such that, it leaves me with a directory like

{'0': 0, '1':0, '2':2, ... , '12':1 }

The values 0, 1, 2 are standing for: do nothing, buy and sell respectively.

Any help, idea or source to gather knowledge from is super appreciated!

dobero
  • 71
  • 5

1 Answers1

0

You can use a f-string to bring in those quotes to your key

cross = [[2, 2], [3, 1], [6, 2], [9, 1], [12, 1]] 

new_dict = {}
new_dict['0'] = 0
new_dict['1'] = 1

for i in cross:
    new_dict[f'"{i[0]}"'] = i[1] 

print(new_dict)
(xenial)vash@localhost:~/python/stack_overflow$ python3.7 nest_dict.py 
{'0': 0, '1': 1, '"2"': 2, '"3"': 1, '"6"': 2, '"9"': 1, '"12"': 1}
vash_the_stampede
  • 4,590
  • 1
  • 8
  • 20