I\'ve already looked at this question on representing strings in Python but my question is slightly different.
Here\'s the code:
>>> class W
Would it work for you if you added an __add__ method? E.g.,
from operator import add
from random import randint
class WeirdThing(object):
def __init__(self,me=None):
self.me = me if me else chr(randint(97,122))
def __str__(self):
return "%s" % self.me
def __repr__(self):
return ";%s;" % self.me
def __add__(self,other):
new_me = add(str(self.me),str(other.me))
return WeirdThing(new_me)
weird_list = [WeirdThing(), WeirdThing(), WeirdThing()]
print weird_list
gives,
[;y;, ;v;, ;u;]
and this,
strange_thing = reduce(add,weird_list)
print strange_thing
gives,
yvu