On Wed, May 14, 2008 at 6:03 PM, Jon Crump <[EMAIL PROTECTED]> wrote: > def events(data): > evts = [] > for x in data: > for y in data: > if (x['placename'] == y['placename']) and (x['end'].month + 1 == > y['start'].month) and (y['start'] - x['end'] == datetime.timedelta(1)): > x['end'] = y['end'] > data.remove(x) > evts.append(x) > return evts > > I understand about removing elements from a container you're iterating. Is > data.remove(x) problematic in this context?
Yes. It can cause the iteration to skip elements ofthe list. Better to post-process the list with a list comprehension: evts = [ evt for evt in evts if 'processed' not in evt ] Kent _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor