Re: Equivalents of Ruby's "!" methods?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • bearophileHUGS@lycos.com

    Re: Equivalents of Ruby's "!" methods?

    Simon Mullis:
    h = { "1" : "a\r", "2" : "b\n" }
    I have the option of an in-place method:
    h.each_value { |v| val.strip! }
    This in-place version may be the closer code for Python 2.x:

    d = {"1": "a\r", "2": "b\n"}
    d.update((k, v.strip()) for k, v in d.iteritems())

    You may also want to use v.rstrip() there instead.

    Bye,
    bearophile
Working...