for x in range(0, 5):
ohlc_list[x] = [open , high , low, close]
This does not do what you think it does. It creates 5 references to the same 4 lists and keep these references under different keys.
This can be shown with this loop:
for value in ohlc_list.values():
print([id(inner_list) for inner_list in value])
# [2446702057416, 2446702057544, 2446692440648, 2446702057480]
# [2446702057416, 2446702057544, 2446692440648, 2446702057480]
# [2446702057416, 2446702057544, 2446692440648, 2446702057480]
# [2446702057416, 2446702057544, 2446692440648, 2446702057480]
# [2446702057416, 2446702057544, 2446692440648, 2446702057480]
We see that all inner lists have the same id
, which mean they all reference the same place in memory (overly simplified on purpose).
What you want is 5 copies of these lists. You can either use an empty slice ([:]
) or copy
to achieve this:
for x in range(0, 5):
ohlc_list[x] = [open[:], high[:], low[:], close[:]]
If we print all the ids of the inner lists again, we see that now we actually got different lists in memory:
# [2592165177544, 2592165177480, 2592165177416, 2592165177352]
# [2592165177672, 2592165177736, 2592165177800, 2592165177864]
# [2592165177992, 2592165178056, 2592165178120, 2592165178184]
# [2592165178312, 2592165178376, 2592165178440, 2592165178504]
# [2592165178632, 2592165178696, 2592165178760, 2592165178824]