Noah Spurrier wrote:
> You want to use map and lamdda. This works on your list: > map(lambda x: x.replace('\n',''), MyList) Why not list comprehensions? Most places where map/filter and lambda are used, a list comp is easier and clearer (and usually faster): MyList = [x.replace('\n','') for x in MyList] > Also remember that Strings have their own replace method, so > if you don't really need to do a regular expression substitution > then String.replace() is faster. This is definately true. String methods are faster and more convenient than regexes, and usually less confusing. ;) Don't use regular expressions unless string methods just can't do what you need. > I always thought lambda expression were hard to read > (mainly I think 'lambda' is an obscure name for most > non-computer science majors) , but at any rate it is a > useful syntax to learn. It's worse than that -- the syntax just looks non-Pythonic. It's harder to remember something that's inconsistent. Plus, a lambda costs as much as a regular function def -- you still have to build the function object, and you still get function-call costs, whereas list comprehensions avoid (most of) those costs. Jeff Shannon Technician/Programmer Credit International _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs