Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
simple key value loop help
#1
Hello,

I have the following python code:

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)
and the results should print out 2: which are Steve and John, however i only see steve printed out... not sure why? any help would be great.

thanks in advance :)
Reply


Messages In This Thread
simple key value loop help - by siten0308 - Jun-24-2019, 08:47 PM
RE: simple key value loop help - by nilamo - Jun-24-2019, 08:49 PM
RE: simple key value loop help - by ankit - Jun-25-2019, 07:45 AM
RE: simple key value loop help - by perfringo - Jun-25-2019, 08:53 AM
RE: simple key value loop help - by siten0308 - Jun-25-2019, 02:53 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Seemingly simple loop Weber585 7 3,565 Mar-21-2021, 07:19 PM
Last Post: jefsummers
  Simple Variable Saving in Loop DevDev 3 3,064 Mar-09-2021, 07:17 PM
Last Post: Fre3k
  simple for loop? gr3yali3n 3 2,562 Sep-22-2020, 05:35 AM
Last Post: buran
  Adding second message to simple loop error PythonGainz 2 2,124 Apr-06-2020, 11:55 AM
Last Post: PythonGainz
  Simple while loop only works on first attempt jsb83 2 2,043 Jun-20-2019, 08:57 PM
Last Post: jsb83

Forum Jump:

User Panel Messages

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