From c3885329ea9ea52c1d60559658df55ba01b3b612 Mon Sep 17 00:00:00 2001 From: smarties Date: Tue, 1 May 2018 15:00:57 +0200 Subject: [PATCH] Added of_enumerate --- mps/__init__.py | 14 ++++++++++++-- mps/of_enumerate.py | 8 ++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) create mode 100644 mps/of_enumerate.py diff --git a/mps/__init__.py b/mps/__init__.py index bfc32de..8c13b30 100644 --- a/mps/__init__.py +++ b/mps/__init__.py @@ -6,6 +6,16 @@ from .mwt import MemoizeWithTimeout from .errorrecoveryfile import ErrorRecoveryFile from .simplecache import SimpleCache +from .of_enumerate import of_enumerate -__all__ = ['randstr', 'hdcache', 'all_days', 'work_days', 'deco_logger', - 'MemoizeWithTimeout', 'ErrorRecoveryFile', 'SimpleCache'] +__all__ = [ + 'randstr', + 'hdcache', + 'all_days', + 'work_days', + 'deco_logger', + 'MemoizeWithTimeout', + 'ErrorRecoveryFile', + 'SimpleCache', + 'of_enumerate', +] diff --git a/mps/of_enumerate.py b/mps/of_enumerate.py new file mode 100644 index 0000000..8c59bad --- /dev/null +++ b/mps/of_enumerate.py @@ -0,0 +1,8 @@ +def of_enumerate(the_list): + zfills = len(str(len(the_list))) + length_list = len(the_list) + for i, item in enumerate(the_list): + i = str(i + 1).zfill(zfills) + yield '{i} / {length_list}'.format(i=i, length_list=length_list), item + + raise StopIteration