Python Forum
General Programming Question with Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General Programming Question with Dictionary
#4
Then the right way to do this is to grab each of the key/value pairs, examine the value and if it needs changing, update it by setting the key to have a new value.

for key, value in cybc.items():
    # evaluate/change the value
    cybc[key] = updated_value(value) # updated_value() needs to return the correct value for your update
The other concern I have is that the value might have a part of a number in it, but your current technique would throw away all the non-number parts. Is that what you want? Or it might have multiple numbers. Let's say one of your values is the string "1894-3999 RT". What do you want the new value to be? It can't be two integers. It could be one of the integers, or it could be a list or a tuple with both integers, or... ?
Reply


Messages In This Thread
RE: General Programming Question with Dictionary - by bowlofred - Jan-07-2022, 07:54 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  python can - general question caslor 0 1,139 Jul-14-2022, 05:21 PM
Last Post: caslor
  a general question barryjo 5 1,557 Feb-01-2022, 10:12 PM
Last Post: Gribouillis
Big Grin General programming question (input string)[ jamie_01 2 1,640 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  Question about formula implementation in general format Alienspecimen 0 1,681 Mar-01-2021, 08:39 PM
Last Post: Alienspecimen
  General list size question to solve problem Milfredo 3 2,391 Sep-27-2020, 08:42 AM
Last Post: Milfredo
  New to programming, loop question tomyan 1 1,674 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  General Listbox question. Milfredo 4 2,206 Sep-06-2020, 07:36 PM
Last Post: Milfredo
  Dictionary question DrZ 2 1,685 Jul-29-2020, 08:53 PM
Last Post: DrZ
  General question about serialization/deserialization in python local 1 1,871 Jan-28-2020, 04:35 AM
Last Post: Larz60+
  General Programming Question Qui_Ten 1 2,214 Jan-14-2019, 11:15 AM
Last Post: steve_shambles

Forum Jump:

User Panel Messages

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