View Single Post
Old Jun 3rd, 2006, 10:39 AM   #6
Sane
Programming Guru
 
Sane's Avatar
 
Join Date: Apr 2005
Location: Waterloo, Ontario
Posts: 2,013
Rep Power: 6 Sane will become famous soon enough
Send a message via MSN to Sane
Thanks a bunch.

class advanced_list(list):
    def __init__(cls, *args):
        setattr(cls, 'len', cls._len)
        setattr(cls, 'filter', cls._filter)
        setattr(cls, 'map', cls._map)
        
        obj = list.__init__(cls, list(args))
        return obj
    
    def _len(self):
        return len(self)

    def _filter(self, func):
        return filter(func, self)

    def _map(self, func):
        return map(func, self)


mylist = advanced_list(1, 2, 3, 4, 5)
print mylist.len()
print mylist.filter(lambda x : (x % 2) == 0)
print mylist.map(lambda x: x * 2)
Sane is offline   Reply With Quote