Equivalents of Ruby's "!" methods?

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Mon Aug 25 16:03:05 CEST 2008


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



More information about the Python-list mailing list