Equivalents of Ruby's "!" methods?

Simon Mullis simon at mullis.co.uk
Mon Aug 25 08:52:24 EDT 2008


Hi All,

Quick question, I can't seem to find the answer online (well, at the
moment I think the answer is a simple "no" but I would like to
confirm).

Consider the following hash:

h = { "1" : "a\r", "2" : "b\n" }

In order to strip the dict values in Python I (think) I can only do
something like:

for k,v in h.items:
    h[k] = v.strip()

While in Ruby - for the equivale dict/hash - I have the option of an
in-place method:

h.each_value { |v| val.strip! }

Are there Python equivalents to the "!" methods in Ruby?

The reason I ask is that I have some fairly complex data-structures
and this would make my code alot cleaner... If this is not an accepted
and pythonic way of doing things then please let me know... and I'll
stop!

Thanks in advance

SM


-- 
Simon Mullis
_________________
simon at mullis.co.uk



More information about the Python-list mailing list