Hi my goal is to convert the dictionary items in the form as commented below -
class MyClass:
def __init__ (self, **kwargs):
self.kwargs=kwargs
def myfunc (self):
sum=0
for x in self.kwargs.items():
sum+=x[1]
return (sum)
d = {"k1": 1, "k2": 2, "k3": 3} # to be converted
ab=MyClass(k1=1, k2=2, k3=3) # so as to be accepted here
ab.myfunc()
Is there any particular operation to be done like here instead of print?
d = {"k1": 1, "k2": 2, "k3": 3}
for i,k in enumerate(d.keys()):
for j,v in enumerate(d.values()):
if i==j:
print(k,v) # some operation to be done here instead of print?
else:
pass