Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @staticmethod
- def __zip_prev_with_new(prev_groups, new_groups):
- from itertools import ifilter
- def drop_tz_unsafe(date):
- return date.replace(tzinfo=None)
- left = map(list, prev_groups)
- right = map(list, new_groups)
- zipped = []
- while len(left):
- old_group = left.pop()
- start_date = drop_tz_unsafe(old_group[0].billing_period_start_date)
- new_groups_iter = ifilter(
- lambda (idx, grp): drop_tz_unsafe(grp[0].billing_period_start_date) == start_date,
- enumerate(right)
- )
- new_group_idx, _ = next(new_groups_iter, (-1, None))
- pair = (old_group, right.pop(new_group_idx)) if new_group_idx >= 0 else (old_group, [])
- zipped.append(pair)
- while len(right):
- zipped.append(([], right.pop()))
- return zipped
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement