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


Groups > comp.lang.python > #22049 > unrolled thread

Re: Odd strip behavior

Started byDaniel Steinberg <dstein64@gmail.com>
First post2012-03-22 15:59 -0400
Last post2012-03-22 15:59 -0400
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

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

#22049 — Re: Odd strip behavior

FromDaniel Steinberg <dstein64@gmail.com>
Date2012-03-22 15:59 -0400
SubjectRe: Odd strip behavior
Message-ID<mailman.907.1332446705.3037.python-list@python.org>
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

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web