Doubts in python code how to use set method -
i excepting elements print prints hffdfd
, fjdkl
. why happens. here's code:
print (set({'hffdfd' : 'shfs', 'fjdkl' : 616}))
because if iterate on dictionary, only obtain keys. next put these keys set print.
you can use following set comprehension print both keys , values:
d = {'hffdfd' : 'shfs', 'fjdkl' : 616} print(set(y x in d.items() y in x))
now construct set contains both keys , values.
if wish print dictionary itself, can use:
print ({'hffdfd' : 'shfs', 'fjdkl' : 616})
Comments
Post a Comment