Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
about cmp fun
#4
(Jan-12-2018, 10:29 AM)Sandesh Wrote: dict = {'Name': 'Zara', 'Age': 7}
print ("Value :" , dict.items())
if i run the above code i supposed to get= Value :([('Name', 'Zara'), ('Age', 7)]).
But i am getting it as=Value : dict_items([('Name', 'Zara'), ('Age', 7)])..
Help me out...

Firstly please use bbcode to wrap you code around. You have better chances of getting help, than one without it.

Quote:
dict = {'Name': 'Zara', 'Age': 7} 
print ("Value :" ,  dict.items()) 
if i run the above code i supposed to get= Value :([('Name', 'Zara'), ('Age', 7)]).
But i am getting it as=Value : dict_items([('Name', 'Zara'), ('Age', 7)])..
Help me out...

And I suspect that your getting this output Value : dict_items([('Name', 'Zara'), ('Age', 7)]). Is because how the __repr__ magic method had been implemented for dict class in python3. In Python2 the output is what you expect. However this has changed in python

>>> dict = {'Name': 'Zara', 'Age': 7} 
>>> dict
{'Age': 7, 'Name': 'Zara'}
>>> dict.items()
[('Age', 7), ('Name', 'Zara')]
Reply


Messages In This Thread
about cmp fun - by Sandesh - Jan-12-2018, 06:54 AM
RE: about cmp fun - by buran - Jan-12-2018, 07:08 AM
RE: about Dictionary - by Sandesh - Jan-12-2018, 10:29 AM
RE: about Dictionary - by hshivaraj - Jan-12-2018, 12:33 PM
RE: about cmp fun - by buran - Jan-12-2018, 07:00 PM
RE: about cmp fun - by Sandesh - Jan-23-2018, 06:22 AM
RE: about cmp fun - by buran - Jan-23-2018, 07:08 AM
RE: about cmp fun - by snippsat - Jan-23-2018, 07:32 AM
RE: about cmp fun - by Sandesh - Jan-26-2018, 05:43 AM
RE: about cmp fun - by snippsat - Jan-26-2018, 06:57 AM
RE: about cmp fun - by buran - Jan-26-2018, 06:58 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020