List - rotate
ameoba
ahmebah at hotmail.com
Fri Jan 25 09:14:35 EST 2002
"Alex Martelli" <aleax at aleax.it> wrote in news:a2mf02$86k$1 at serv1.iunet.it:
> s[1:]+s[0:1] yields a "rotated copy" for ANY sequence s, be it
> a string, a list, a tuple, whatever. But you need to
> assign it to something, else it will go away as soon
> as you're done with it. It does NOT modify s in-place
> in any case (strings and tuples are mutable, lists are
> mutable but no mutation is performed in this case).
Of course, this is easily abstractable to rotating a list by any arbitrary
ammount... But it got me to wondering; is there a good way to add a
method to strings?
Not so much to make a class derived from the string type, but just to add a
function to it.
If it can't be done with a built-in class like string, can methods be added
to user-defined classes outside of the original class definition without
subclassing them?
Not so much that I want to do this, just that I'm curious as to how dynamic
of an environment Python really is.
More information about the Python-list
mailing list