You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fromfunctoolsimportpartialfromoperatorimportitemgetterannotator=partial(enumerate)
deannotator=partial(map, itemgetter(1))
assertlist(annotator('abc')) == [(0, 'a'), (1, 'b'), (2, 'c')]
assertlist(deannotator([(0, 'a'), (1, 'b'), (2, 'c')])) == ['a', 'b', 'c']
# But list is not the right iterator aggregator for this; ''.join is.''.join(deannotator([(0, 'a'), (1, 'b'), (2, 'c')])) =='abc'
with time
importtimedefadd_time(x):
returntime.time(), xannotator=partial(map, add_time)
deannotator=partial(map, itemgetter(1)) # same as the index counterlist(annotator('abc'))
# [(1637094309.799298, 'a'), (1637094309.799298, 'b'), (1637094309.799298, 'c')]assert''.join(deannotator(annotator('abc'))) =='abc'