Jump to content

Check out our Community Blogs

Register and join over 40,000 other developers!

Recent Topics

Recent Status Updates

View All Updates

- - - - -

Print specific values from dictionary with a specific key name

dictionary key value python

This topic has been archived. This means that you cannot reply to this topic.
No replies to this topic

#1 Siten0308


    CC Addict

  • Advanced Member
  • PipPipPipPipPip
  • 298 posts

Posted 20 June 2019 - 01:43 PM



very simple python example, trying to re-learn python, hopefully it goes well :)


i have a simple dictionary:

d = {'123':'John','123':'Steve','4929':'959','3491':'5','319':'Bob','name': 'john','code':6734, 'dept': 'sales'}

for k, v in d.items():
   if(k == '123'):
     print (v)

looking above, just want to print 2 rows, which have the specific key 123, so it should print John and Steve, however it only prints steve? why and how can i accomplish this?


thanks in advance :)


Its only funny till someone gets hurt.... THEN ITS HILARIOUS :)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download