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 8677133
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T20:22:38+00:00 2026-06-12T20:22:38+00:00

I have a dictionary of synonyms: synonym = {this: [this, same], all: [all, any,

  • 0

I have a dictionary of synonyms:

synonym = {"this": ["this", "same"],
           "all": ["all", "any", "*"],
           "alluptolastyear": ["alluptolastyear", "uptolastyear"],
           "dekadbefore": ["dekadbefore", "lastdekad", "formerdekad", "precedingdekad"],
           "dekadafter": ["dekadafter", "nextdekad", "followingdekad"],
           "yearbefore": ["yearbefore", "lastyear", "formeryear"],
           "monthbefore": ["monthbefore", "lastmonth", "precedingmonth"]}

Each array stores synonyms, referenced through the keys.
I read two strings from an XML file, and try to compare them.

For example:

  • "this" and "same" are equal (synonyms)
  • ‘”lastyear”‘ and ‘”formeryear”‘ are equal (synonyms)
  • "all" and "nextdekad" are different
  • of course, each key value is found in its corresponding array, so each key is a synonym of its array’s strings.

Could some help me to write a pythonic comparison of those strings using the synonym dictionary?

  • 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-06-12T20:22:41+00:00Added an answer on June 12, 2026 at 8:22 pm

    Try this:

    def are_sinonims(a, b):
        return a in synonym.get(b,[]) or b in synonym.get(a,[]) or any(a in synonym[k] and b in synonym[k] for k in synonym)
    

    Also, we can rewrite the part a in synonym[k] and b in synonym[k] for k in synonym to a in words and b in words for words in synonym.values() such that:

    def are_sinonims(a, b):
        return a in synonym.get(b,[]) \
               or b in synonym.get(a,[]) \
               or any(a in words and b in words for words in synonym.values())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have json like this (have dictionary and array). I want draw all json
I have a dictionary, user_dict, and create a list for each user value, this
i have this dictionary: a) 2012 UN NEWNW = ( 2012/06/04 Saudi Arabia Huge
I have a dictionary in my database which has over million records and this
I am working on a simple dictionary where I have words and synonyms to
I have to do a synonyms dictionary using a TreeMap. The TreeMap is of
Suppose I have Dictionary like this: Dictionary<string, string> values = new Dictionary<string, string>() {
I have Dictionary<long, Location> PostalCodes . While i m adding new elements to this
I have a dictionary of about 50,000 words; each word has-many synonyms, antonyms, etc.
I have a Dictionary of Dictionarys of Array of Objects. Just like this: 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.