a = ['2023-02-10T00:00:35Z2023-02-13T00:00:00Z', '2023-02-06T09:03:24Z2023-02-13T00:00:00Z', '2023-02-11T19:27:55Z2023-02-18T19:00:00Z', '2023-02-12T18:00:00Z2023-02-13T04:00:00Z', '2023-02-12T18:00:51Z2023-02-19T00:00:00Z', '2023-02-12T20:00:00Z2023-02-13T01:00:00Z']
b = [['2023-02-10', '2023-02-11', '2023-02-12'], ['2023-02-10', '2023-02-11', '2023-02-12'], ['X', '2023-02-11', '2023-02-12'], ['X', 'X', '2023-02-12'], ['X', 'X', '2023-02-12'], ['X', 'X', '2023-02-12']]
I have two lists above, length of both the lists is always same and second list will always be a list of lists.
I would like to replace dates of list b
with either 1, 0.5 or 0
based on the date time range given in list a
.
First list of list b
will correspond to first element of list a
i.e date and time ranges , second list of list b
will correspond to second element of list a
and so on.
So I need to compare only nth element of list b
(list) with nth element of list a
(datetime range)
Desired output will be list b
with below values.
b = [[1,1,1],[1,1,1],['X',0.5,1],['X','X',0.5],['X','X',0.5],['X','X',0.5]
Criteria : value 1 when whole 24 hours is completed for a given date; value 0.5 when < 24 hours and greater than 0 ; value 0 when 0 hours.
I am thinking of using slicing to compare dates from list a like below:
for l in b:
for i,x in enumerate(l):
for k in a:
if x == k.split('T')[0]:
if k.split('T')[1][:2] != '00':
######
But I am not really sure whether this will work especially when I want to compare 1 to 1 elements.
Answers here states how to iterate over lists in parallel but how to iterate if one is list and another is a list of lists?
Any help would be appreciated.
Thanks.