Python Forum
General Programming Question with Dictionary
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
General Programming Question with Dictionary
#8
Line 6 won't work. You're asking if the current value is a match object. I presume that your current values are strings, so that won't ever succeed.

You're using "findall", but findall only hands you the bits that match, not the non-digit bits (which you presumably want to retain). Possibly you want to use re.sub instead. Then if your num2words can take a match object instead of an int, you could write it as:

sub match2words(m):
    digits = m.group()
    # convert this with whatever means you have
    return "converted"

for key, value in cybc.items():
    new_value = re.sub(r'\d+', match2words, value)
    cybc[key] = new_value
    print('Test to show updated value', new_value)
    print('Test to show keys', key)
Reply


Messages In This Thread
RE: General Programming Question with Dictionary - by bowlofred - Jan-07-2022, 09:38 PM

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,639 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,388 Sep-27-2020, 08:42 AM
Last Post: Milfredo
  New to programming, loop question tomyan 1 1,673 Sep-25-2020, 04:32 PM
Last Post: Larz60+
  General Listbox question. Milfredo 4 2,199 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,212 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