O'Reilly Forums: Using A Hash - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Using A Hash Associate a key with a value using a hash

#1 User is offline   hanken11 

  • New Member
  • Pip
  • Group: Members
  • Posts: 1
  • Joined: 18-October 12

Posted 18 October 2012 - 10:35 AM

I am having trouble with associating a key with a value using a hash. When I run the module this is the error message I get

Traceback (most recent call last):
File "C:/Python33/scores2.py", line 5, in <module>
for score, surfer in scores.item():
AttributeError: 'dict' object has no attribute 'item'

Here is the code

scores = {}
scores [8.45] = 'Joseph'
scores [9.12] = 'Juan'
scores [7.12] = 'Zack'
for score, surfer in scores.item():
print(surfer + ' had a score of ' + str(score))

If someone could please advise it would be appreciated.

Thanks
0

#2 User is offline   paulbarry 

  • Advanced Member
  • PipPipPipPipPipPipPip
  • Group: O'Reilly Author
  • Posts: 251
  • Joined: 20-August 09

Posted 17 November 2012 - 03:41 AM

Your code should read "scores.items()", not "scores.item()", as per page 154 in the book.

--Paul.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users