Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6608513
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:37:04+00:00 2026-05-25T19:37:04+00:00

I am trying to build a dictionary with frequent terms for my website. So

  • 0

I am trying to build a dictionary with frequent terms for my website. So basically I will retrieve a paragraph from my database and this paragraph most likely will contain terms which appear in the aforementioned dictionary. What I am looking for is a nice way (and fast) to parse the paragraph text and map the dictionary terms which might appear in that text with the dictionary entries.

Is there a Python module which can assist me with this task? I am not looking for something fancy but it must be fast.

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T19:37:05+00:00Added an answer on May 25, 2026 at 7:37 pm

    Something like this?

    >>> s = "abc def, abcdef"
    >>> w = {"abc": "xxx", "def": "yyy"}
    >>> def replace(text, words):
    ...     regex = r"\b(?:" + "|".join(re.escape(word) for word in words) + r")\b"
    ...     reobj = re.compile(regex, re.I)
    ...     return reobj.sub(lambda x:words[x.group(0)], text)
    ...
    >>> replace(s, w)
    'xxx yyy, abcdef'
    

    Note that this only works reliably if all the dictionary’s keys start and end with a letter (or a digit or underscore). Otherwise, the \b word boundaries fail to match.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to build a pie chart from a dictionary. Before I display
I was trying Build For Archiving application (from Titanium Mobile) with xCode 4.4, but
I'm trying build a method which returns the shortest path from one node to
Trying to build openssl-fips-2.0 with NDK, before I was lucky found this link and
I am trying to build an array that contains arrays of dictionary objects in
I'm trying to build template tags that take use a dictionary in settings.py to
I'm trying to build words in arrays by their key value in a dictionary.
I am trying to build a dictionary with two keys but am getting a
I am trying to build an autocomplete script. The dictionary is on a separate
I found a dictionary of Chinese characters in unicode. I'm trying to build a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.