Hey,
I have several lists that I would like to map together, but I can't quite work my head around how to do it.
I am scraping a live feed of Horse Racing results. The feed only lists the course/time once and three horses and their positions (top three) OR four horses and blank (i.e. "") positions IF the race was abandoned. These are the lists I have:
course, time, abandoned, horses, position
The lists are in order.
course
, time
and abandoned
all have exactly the same number of elements (abandoned is a list of booleans, True meaning that race was abandoned).
horses
is a list of the (3 * number of non abandoned races) + (4 * number of abandoned races) horses.
position
is a list of the place positions of the horses. If a race was abandoned the position will be "", otherwise it is "1", "2", "3" (strings!).
Example Lists:
Where no race was abandoned
course = ["Course A", "Course A", "Course B"] #there were two races at course A
times = ["00:00", "01:00", "15:00"] #Race 1 at Course A was at 00:00, race 2 at course A was at 01:00
horses = ["HorseA 1", "HorseA 2", "HorseA 3", "HorseA 4", "HorseA 5", "HorseA 6", "HorseB 1", "HorseB 2", "HorseB 3"] #There are three horses per race
positions = ["1","2","3","1","2","3","1","2","3"]
So, at Course A in the race at 00:00 "HorseA 1" came 1st, "HorseA 2" came 2nd and "HorseA 3" came 3rd.
Where there was an abandoned race
courses = ["CourseX", "CourseX", "CourseY"]
times = ["01:00", "02:00", "01:00"]
abandoned = [False, False, True]
horses = ["X1", "X2", "X3", "X4", "X5", "X6", "Y1", "Y2", "Y3", "Y4"]
positions = ["1","2","3","1","2","3","","","",""]
So, there were two races at CourseX but the race at CourseY was abandoned.
What I want to end up with is a list of tuples like so:
[(A Race Course, 00:00, False, Horsey, 1), (A Race Course, 00:00, False, Horsey 2, 2) ... ]
I'm not sure how I can do so, suggestions?
Cheers,
Pete