a = [('08:57', 'Edinburgh', '12:08'), ('12:08', 'London', '12:50'), ('12:50', 'London', 14:44')]
So I have lists of times (these are bus journeys) like 'a' above and each tuple contains the start and stop time of the leg and a station name. However, they also sometimes contain legs which are just 'waiting at the bus station' legs. These can be identified by the fact that the start time is identical to the stop time of the previous leg and the stop time is identical to the start time of the following leg. I want to identify these and then delete them. I wondered about sets, but the bus station naming screws that up and then I wondered about generators.
So something crude like:
gen = (item for item in a) #turn list into generator object
try:
while 1:
if gen.next()[2] == gen.next()[0] and gen.next()[0]:
print 'match'
except StopIteration:
print 'all done'
does work but it's naff and doesn't allow me to identify the index position of the original tuple to delete it.
Would really appreciate an approach to this.