Например так:
accounts = []
with open('in', 'r') as f:
lines = f.read().splitlines()
for account, times in zip(lines[::2], lines[1::2]):
accounts.extend([(time.strip("' "), account) for time in times.split(',')])
for time, account in sorted(accounts):
print account
Ну или покороче:
with open('in', 'r') as f:
lines = f.read().splitlines()
accounts = [(time.strip("' "), account) for account, times in zip(lines[::2], lines[1::2])
for time in times.split(',')]
for time, account in sorted(accounts):
print account
Или так:
accounts = []
with open('in', 'r') as f:
try:
while True:
account, times = f.next().strip(), f.next().strip()
accounts.extend([(time.strip("' "), account) for time in times.split(',')])
except StopIteration:
pass
for time, account in sorted(accounts):
print account
Соответственно, предвосхищая возможный вопрос, если формат даты или требования к сортировке меняются, вам нужно будет просто написать свою функцию сравнения и вставить её в sorted.