Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #22049

Re: Odd strip behavior

From Daniel Steinberg <dstein64@gmail.com>
Subject Re: Odd strip behavior
Date 2012-03-22 15:59 -0400
References <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.907.1332446705.3037.python-list@python.org> (permalink)

Show all headers | View raw


strip() removes leading and trailing characters, which is why the 't' in 
the middle of the string was not removed. To remove the 't' in the 
middle, str1.replace('t','') is one option.

On 3/22/12 3:48 PM, Rodrick Brown wrote:
> #!/usr/bin/python
>
> def main():
>
>      str1='this is a test'
>      str2='t'
>
>      print "".join([ c for c in str1 if c not in str2 ])
>      print(str1.strip(str2))
>
> if __name__ == '__main__':
>      main()
>
> ./remove_str.py
> his is a es
> his is a tes
>
> Why wasnt the t removed ?
> Sent from my iPhone

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Odd strip behavior Daniel Steinberg <dstein64@gmail.com> - 2012-03-22 15:59 -0400

csiph-web