You want to use map and lamdda. This works on your list:
map(lambda x: x.replace('\n',''), 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.

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.

Yours,
Noah

----- Original Message -----
From: "A" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]>;
<[EMAIL PROTECTED]>
Sent: Saturday, April 06, 2002 12:31 PM
Subject: How to remove a newline character


> Hi,
> Can you please let me know  if it is possible to replace
> new line characters( '\n') in a list in one step?
>
> I have list like
>
> MyList=['272580\n', '23232432\n']
>
> and I would like to have
> ,MyList=['272580', '23232432']
>
> so I tried
> re.sub('\n','',MyList)
> but I received
> TypeError: expected string or buffer
>
> Your help would be appreciated
> Thanks.
> Ladislav
>
> I look forward to hearing from you soon.
>
> Best Regards,
> Ladislav Blazek( Mr.)
>
> BMA TRADING Ltd.
> email: [EMAIL PROTECTED]
> email2: [EMAIL PROTECTED]
> Fax:/Tel +420 506 447921
> Tel:+420 506 447920, +420 602 849309
>
>
> _______________________________________________
> 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

Reply via email to