I have an array of dictionaries in following format.
myarary = {day = 0; hour = 1; value = 0;},{day = 0; hour = 2; value = 0;}.... {day 6 =1; hour =23; value =1;}
So basically 7 days, 24 hours for each day and values 1 or 0 for each hour. hence total of 168 dictionaries in my array.
Now my task is to extract values for a range of hours for a given day. For example, for day 6 I would have to extract hours slot between 2, 9 and another slot between 15 and 18 and so on.
I manage to solve the problem, with a nest for loop in following format
for (i =< start_of_hour_slot;i=<last_hour_of_slot); i++)
for(j = 0; j<=6; j++)
Now this works, but its too lengthy and my code is filled with loops, there must be easier way with fast enumeration?
Secondly my for loops doesn't give me flexibility.
I like to be in a position, where I can simply extract lets say for day 7, three different hours slots, along side the values.
or maybe for multiple days like, day 3,4,5 slots 2-9, 11,15...
You can change your array size and format, since your data is clear, just need to make the array size to 168, and put the value 0 or 1 directly into the array. The first 24 elements put the array the day0 values, and the next 24 elements put the day1 values, ..., the last 24 elements put the day6 values. If you want to extract the values of day 3,4,5 slots 2-9, 11,15, just fetch the elements index of 3*6+2 ~ 3*6+9, 4*6+11, 5*6+15 in the array.