Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Drop Keys From Dictionary
#6
(May-30-2020, 09:55 AM)WiPi Wrote: Here's another straightforward method

dictOfVals = {1: 0.2, 2: -0.1, 3: 2, 4: 0.1, 5: 0.05}

newDict=dict()
# Iterate over all the dict values
for value in dictOfVals.values():
   if value > 0.1 or value < -0.1:
     print(value)

How would I also get the corresponding key for each value?
Reply


Messages In This Thread
Drop Keys From Dictionary - by donnertrud - May-30-2020, 09:24 AM
RE: Drop Keys From Dictionary - by Knight18 - May-30-2020, 09:47 AM
RE: Drop Keys From Dictionary - by donnertrud - May-30-2020, 09:49 AM
RE: Drop Keys From Dictionary - by DreamingInsanity - May-30-2020, 09:50 AM
RE: Drop Keys From Dictionary - by WiPi - May-30-2020, 09:55 AM
RE: Drop Keys From Dictionary - by donnertrud - May-30-2020, 10:00 AM
RE: Drop Keys From Dictionary - by Yoriz - May-30-2020, 10:26 AM
RE: Drop Keys From Dictionary - by donnertrud - May-30-2020, 10:53 AM
RE: Drop Keys From Dictionary - by DeaD_EyE - May-30-2020, 11:39 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Adding keys and values to a dictionary giladal 3 2,486 Nov-19-2020, 04:58 PM
Last Post: deanhystad
  access dictionary with keys from another and write values to list redminote4dd 6 3,249 Jun-03-2020, 05:20 PM
Last Post: DeaD_EyE
  Problem adding keys/values to dictionary where keynames = "property" and "value" jasonashaw 1 2,050 Dec-17-2019, 08:00 PM
Last Post: jasonashaw
  Checking if the combination of two keys is in a dictionary? mrsenorchuck 6 3,894 Dec-04-2019, 10:35 AM
Last Post: mrsenorchuck
  Retrieving dictionary keys within with another dictionay bazcurtis 8 2,828 Oct-29-2019, 10:06 PM
Last Post: bazcurtis
  json.dumps to keep dictionary keys batchenr 1 2,015 May-14-2019, 11:17 AM
Last Post: buran
  Reference new dictionary keys with a variable slouw 4 2,898 May-07-2019, 03:30 AM
Last Post: slouw
  Get specific key from multiple keys in python dictionary pradeepkumarbe 0 2,125 Mar-24-2019, 07:23 PM
Last Post: pradeepkumarbe
  Most efficient way to define sub keys of a dictionary? wrybread 1 2,118 Feb-21-2019, 12:23 AM
Last Post: snippsat
  Need help for extractring keys from dictionary dragan979 3 3,007 Jan-23-2019, 02:44 PM
Last Post: buran

Forum Jump:

User Panel Messages

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