# Re[2]: [Tutor] map, filter and lambda functions

Kerim Borchaev Kerim Borchaev" <warkid@storm.ru
Thu, 23 Aug 2001 12:02:17 +0400

```Thursday, August 23, 2001, 9:23:50 AM, you wrote:

RR> checklist = string.split(filetext, '\n')
RR> checklist = filter(None, checklist)
RR> checklist = map(string.strip, checklist)
RR> checklist = map(string.upper, checklist)

RR> If checklist is rather long, the last two may be written mor efficiently
RR> as:

RR> checklist = map(lambda x:string.upper(string.strip(x)), checklist)

About efficiency - running the script below i get this:

2.01
1.32
2.01
1.32

no luck for lambda...

-------------
import time

l=[str(x) for x in range(1000)]

num_iter=100

import string

start = time.clock()
for i in range(num_iter):
checklist=l
checklist = map(string.strip, checklist)
checklist = map(string.upper, checklist)
stend = time.clock()
print "%.2f"%(stend-start)

start = time.clock()
for i in range(num_iter):
checklist=l
checklist = map(lambda x:string.upper(string.strip(x)), checklist)
stend = time.clock()
print "%.2f"%(stend-start)

start = time.clock()
for i in range(num_iter):
checklist=l
checklist = map(string.strip, checklist)
checklist = map(string.upper, checklist)
stend = time.clock()
print "%.2f"%(stend-start)

start = time.clock()
for i in range(num_iter):
checklist=l
checklist = map(lambda x:string.upper(string.strip(x)), checklist)
stend = time.clock()
print "%.2f"%(stend-start)
-------------

Best regards,
Kerim                            mailto:warkid@storm.ru

```