[Tutor] How to remove a newline character

alan.gauld@bt.com alan.gauld@bt.com
Sun, 7 Apr 2002 23:02:17 +0100


> MyList=['272580\n', '23232432\n']
> 
> and I would like to have 
> MyList=['272580', '23232432']

MyList = map(lamda s: s.strip(), MyList)

Or more explicitly

for n in range(len(MyList)): 
    MyList[n] = MyList[n].strip()


If you don't want to use strip then just use slicing to 
get rid of the last char:

    MyList[n] = MyList[n][:-1]  # strip off last char

Alan G