This commit is contained in:
Martin Diehl 2021-03-31 14:27:36 +02:00
parent 7b678af1b4
commit 97e6c397d9
1 changed files with 12 additions and 16 deletions

View File

@ -131,11 +131,15 @@ def show_progress(iterable,N_iter=None,prefix='',bar_length=50):
Character length of bar. Defaults to 50. Character length of bar. Defaults to 50.
""" """
status = _ProgressBar(N_iter if N_iter is not None else len(iterable),prefix,bar_length) if N_iter == 1 or len(iterable) == 1:
for item in iterable:
yield item
else:
status = _ProgressBar(N_iter if N_iter is not None else len(iterable),prefix,bar_length)
for i,item in enumerate(iterable): for i,item in enumerate(iterable):
yield item yield item
status.update(i) status.update(i)
def scale_to_coprime(v): def scale_to_coprime(v):
@ -431,19 +435,11 @@ def dict_compress(d):
""" """
if isinstance(d,dict) and len(d) == 1: if isinstance(d,dict) and len(d) == 1:
key = list(d.keys())[0] entry = d[list(d.keys())[0]]
entry = d[key] new = dict_compress(entry.copy()) if isinstance(entry,dict) else entry
if isinstance(entry,dict):
new = dict_compress(entry.copy())
else:
new = entry
else: else:
new = {} new = {k: (dict_compress(v) if isinstance(v, dict) else v) for k,v in d.items()}
for k,v in d.items():
if isinstance(v, dict):
v = dict_compress(v)
if not isinstance(v,dict) or v == {}:
new[k] = v
return new return new