classObjectSpecial:def__init__(self,dictLike):# sort the dictionary with respect to keys
# so now keys will be sorted in alphabetical order
self.dictLike=dict(sorted(dictLike.items()))def__getattr__(self,s):# if any key starts with s then return the corresponding value
# if key not found return 0
fork,vinself.dictLike.items():if(k.startswith(str(s))):returnvreturn0partialKey=lambdadictLike:ObjectSpecial(dictLike)d={'abcd':1,'abbd':2,'abdd':3}o=partialKey(d)print(o.a)# output : 2
print(o.ab)# output : 2
print(o.abcd)# output : 1
print(o.abd)# output : 3
print(o.k)# output : 0 as key not present
print(o.ac)# output : 0 as key not present
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Python approach