Simon Mullis:
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
h = { "1" : "a\r", "2" : "b\n" }
I have the option of an in-place method:
h.each_value { |v| val.strip! }
I have the option of an in-place method:
h.each_value { |v| val.strip! }
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