Yes indeed. I didn't think of list comprehensions until after I sent the response. That syntax is still new to me -- I only wrote my first list comprehension a month ago! It is a much more clear and Pythonic syntax. I wish that answer had come to my mind first, but I've still got map and lambda on the brain.
Thanks, Noah ----- Original Message ----- From: "Jeff Shannon" <[EMAIL PROTECTED]> To: "activepython list" <[EMAIL PROTECTED]> Sent: Monday, April 08, 2002 10:22 AM Subject: Re: How to remove a newline character > > 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 > _______________________________________________ ActivePython mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs