Skip to content

Instantly share code, notes, and snippets.

@h3ik0th
Created Oct 15, 2021
Embed
What would you like to do?
# comprehensions vs lambda-filters
t = time.perf_counter()
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
strLamb = filter(lambda d: ((d.endswith("urday") or d.endswith("unday")) and "Oc" in d), datstrlist)
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tLamb = time.perf_counter() - t
print(f'{tLamb:.4f} sec')
t = time.perf_counter()
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
c = [d for d in datstrlist if ((d.endswith("urday") or d.endswith("unday")) and "Oc" in d)]
# >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
tComp = time.perf_counter() - t
print(f'{tComp:.4f} sec: comprehension vs lambda-filter: {100*(tComp/tLamb-1):.1f}%')
df = pd.DataFrame(list(zip(strLamb,c)), columns=("lambda","comprehension"))
df
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment