Open Metric
Science, Fiction and Me

Today I Learned

Python Map vs For in Python

map is sometimes more convinient instead of for. The code

newlist = []
for word in oldlist:

can be reformed using map

newlist = map(str.upper, oldlist)

for loop is sometimes slow because the dot evaluation inside is evaluated for each loop. Thus the following code is more efficient.

upper = str.upper
newlist = []
append = newlist.append
for word in oldlist:

A Random #TIL# for You

Most technical TILs will be updated at

By OctoMiao

Last updated