[Tutor] map, filter and lambda functions
Danny Yoo
dyoo@hkn.eecs.berkeley.edu
Wed, 22 Aug 2001 18:02:41 -0700 (PDT)
> Here is an earlier version of a part of the code:
>
> checklist = string.split(filetext, "\n")
> for item in checklist:
> if item != '':
> itemIdx = checklist.index(item)
> item = string.strip(item)
> item = string.upper(item)
> checklist[itemIdx] = item
> else:
> checklist.remove(item)
>
>
> Here's the new, shorter version:
>
> checklist = string.split(filetext, "\n")
> checklist = filter(lambda x: x != '', checklist)
> checklist = map(lambda x: string.strip(x), checklist)
> checklist = map(lambda x: string.upper(x), checklist)
Yes, this looks good! Glad it clicks now!