1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| from collections import defaultdict
class azzuri(object) :
def __init__(self):
self.wx = defaultdict(lambda: defaultdict(int))
self.wy = defaultdict(int)
def aug(self,*arg):
if len(arg)==2: object.__getattribute__(self, 'wx')[arg[0]][arg[1]] += 1
elif len(arg)==1: object.__getattribute__(self, 'wy')[arg[0]] += 1
else: print 'Il ne peut pas y avoir plus de deux arguments'
def __getattribute__(self,name):
if name=='wx':
return dict((k,dict(di))
for k,di in object.__getattribute__(self, name).iteritems())
if name=='wy':
return dict(object.__getattribute__(self, name))
if name=='aug':
return object.__getattribute__(self, name)
def __repr__(self):
return 'dik.wx = '+repr(self.wx)+'\ndik.wy = '+repr(self.wy)
dik = azzuri()
print 'dik.wx :',dik.wx
print 'dik.wy :',dik.wy
print
print 'dik :\n',dik
print '-----'
dik.aug(34,'qw')
dik.aug('kili')
dik.aug(887,'balance')
dik.aug(34,'hoof')
dik.aug(34,'qw')
dik.aug('plage')
dik.aug('kili')
print
print 'dik :\n',dik |
Partager