Python Forum
AttributeError: module 'string' has no attribute 'uppercase'
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
AttributeError: module 'string' has no attribute 'uppercase'
#9
(Apr-23-2021, 10:49 AM)ibreeden Wrote: If I understand your logic well, you are first adding all words to a dictionary. Then you are doing a lot of work to inspect the dictionary and move the words starting with a capital to the same word in lower case and delete the word starting with a capital.
My advice would be: make all keys lower case in the first place. Then the dictionary needs no post-processing.
    freq = {}
    for sentence in sentences:
        words = re.split(r"[^a-zA-Z0-9-]+", sentence)
        for word in words:
            count = freq.get(word.lower(), 0)
            freq[word.lower()] = count + 1
Reply


Messages In This Thread
RE: AttributeError: module 'string' has no attribute 'uppercase' - by Anldra12 - Apr-23-2021, 02:22 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  trouble reading string/module from excel as a list popular_dog 0 512 Oct-04-2023, 01:07 PM
Last Post: popular_dog
  getpass.getpass() results in AttributeError: module 'os' has no attribute 'O_NOCTTY' EarthAndMoon 4 1,007 Oct-03-2023, 02:00 PM
Last Post: deanhystad
  AttributeError: '_tkinter.tkapp' object has no attribute 'username' Konstantin23 4 2,286 Aug-04-2023, 12:41 PM
Last Post: Konstantin23
  Parallel processing - AttributeError: Can't get attribute 'sktimekmeans' Mohana1983 1 901 Jun-22-2023, 02:33 AM
Last Post: woooee
  Python: AttributeError: 'PageObject' object has no attribute 'extract_images' Melcu54 2 4,570 Jun-18-2023, 07:47 PM
Last Post: Melcu54
  cx_oracle Error - AttributeError: 'function' object has no attribute 'cursor' birajdarmm 1 2,771 Apr-15-2023, 05:17 PM
Last Post: deanhystad
  File "<string>", line 19, in <module> error is related to what? Frankduc 9 12,960 Mar-09-2023, 07:22 AM
Last Post: LocklearSusan
  Pandas AttributeError: 'DataFrame' object has no attribute 'concat' Sameer33 5 6,404 Feb-17-2023, 06:01 PM
Last Post: Sameer33
  AttributeError: 'numpy.ndarray' object has no attribute 'load' hobbyist 8 7,522 Jul-06-2022, 10:55 AM
Last Post: deanhystad
  AttributeError: 'numpy.int32' object has no attribute 'split' rf_kartal 6 4,781 Jun-24-2022, 08:37 AM
Last Post: Anushka00

Forum Jump:

User Panel Messages

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