Python Forum
updating certain values in dict. with relation to their keys
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
updating certain values in dict. with relation to their keys
#1
Hi all
just joined
I have a very annoying problem
I have a dictionary containing key value pairs that are all integers.
I want to check if some values equal a number, and if so, the value of each of these items will be changed with relation to its key.
and if no value matches the current number a new item is created
relevant piece of code:


for key, value in mydict.items():
if value == current:
value = value + 3 * key
if current not in mydict:
mydict[current:current * 2]

thank you all
this does not work
I need the correct synthax...
Reply


Messages In This Thread
updating certain values in dict. with relation to their keys - by malevy - Nov-27-2019, 07:06 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
Question Chain object that have parent child relation.. SpongeB0B 10 1,295 Dec-12-2023, 01:01 PM
Last Post: Gribouillis
  logging values from constantly updating CLI app imvirgo 1 593 Sep-27-2023, 05:01 PM
Last Post: deanhystad
  Updating Code And Having Issue With Keys Xileron 8 1,388 May-25-2023, 11:14 PM
Last Post: DigiGod
  dict class override: how access parent values? Andrey 1 1,738 Mar-06-2022, 10:49 PM
Last Post: deanhystad
  Updating nested dict list keys tbaror 2 1,358 Feb-09-2022, 09:37 AM
Last Post: tbaror
  Loop Dict with inconsistent Keys Personne 1 1,680 Feb-05-2022, 03:19 AM
Last Post: Larz60+
  Removing nan values from a dict tomtom 8 7,474 Oct-05-2021, 06:44 PM
Last Post: tomtom
  Create Dict from multiple Lists with duplicate Keys rhat398 10 4,234 Jun-26-2021, 11:12 AM
Last Post: Larz60+
  Values not updating for restful call boomramada 0 1,702 Mar-13-2021, 01:08 PM
Last Post: boomramada
  Adding keys and values to a dictionary giladal 3 2,617 Nov-19-2020, 04:58 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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