def finddepth(dictA): if isinstance(dictA, dict): return 1 + (max(map(finddepth, dictA.values())) if dictA else 0) return 0 dictA = {1: 'Sun', 2: {3: {4:'Mon'}}} print("The depth of dictionary: ",finddepth(dictA))