I have generator cut_slices
and use for
loop. But I need to do some specific work with the first and last yielding elements outside the loop. With first it's easy, just use next()
before loop. But what with last?
fu_a = self.cut_slices(unit, unit_size) #generator (simple for loop with some calculations and yield)
header = self.make_header(p=0, first_byte=unit[0], rtp_type=rtp_type, flag='s')
self.send_packet(header + next(fu_a))
for i in fu_a: #if there is an analogue of a[:-1] for generator object?
header = self.make_header(p=0, first_byte=unit[0], rtp_type=rtp_type,
flag='m')
self.send_packet(header + i)
header = self.make_header(p=0, first_byte=unit[0], rtp_type=rtp_type, flag='e')
self.send_packet(header + next(fu_a))
P.S. I understand that there are other ways to achieve the same result, just want to figure out.