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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:56:19+00:00 2026-05-30T10:56:19+00:00

I am importing a dictionary file containing words that I read in as an

  • 0

I am importing a “dictionary” file containing words that I read in as an array. I then want to search a 6 word phrase being generated by a permutation function for each one of those words and print out if a match is found from the dictionary array to any of the words in the phrase. If I could print out only if it finds matches for the whole phrase that would be preferable. The output of the permutation results in a string of 6 words separated by spaces.

Thanks

import itertools
import array
arr=[]
f = file('/home/kyle/dictionary.csv').readlines()
for i in range(len(f)):
    arr.append(f[i].rstrip('\n').rstrip('\r').split(','))

for a in range(0, len(arr)):
    print arr[a]

s=['e','k','y','a','v','y','a','a','o','s','r','h','t','n','i','k','h','t','s','t','e','n','i','p','p','l','e','h','d','c','t','e','f','a','t','t','l']
for L in range(1, len(s)+1):
for subset in itertools.permutations(s, 37):
    x=( "".join(subset))
    s=x[:5] + ' ' + x[5:]
    s=s[:16] + ' ' + s[16:]
    s=s[:20] + ' ' + s[20:]
    s=s[:27] + ' ' + s[27:]
    s=s[:31] + ' ' + s[31:]
    s=s[:35] + ' ' + s[35:]
    for c in range(0,len(arr)):

        test=str(arr[c])
        if test in s:
            print s

The bottom part was playing with “in” to find possible matches but that didn’t seem to turn out any results. The code is pretty messy

  • 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-30T10:56:21+00:00Added an answer on May 30, 2026 at 10:56 am

    Hope this helps, this is a very naive implementation, but might be useful as a start point.

    In [2]: words = ['word1', 'word2', 'word3', 'word4', 'word5', 'word6', 'word7']
    
    In [3]: phrase1 = 'bla bla word1 bla word2 bla word7'
    
    In [4]: phrase2 = 'bla bla word1 bla word2 bla word7 word6, word4 word3'
    
    In [5]: def match(phrase):
       ...:     n_matches = 0
       ...:     for w in words:
       ...:         if w in phrase:
       ...:             n_matches += 1
       ...:     return n_matches == 6
       ...: 
    
    In [6]: match(phrase1)
    Out[6]: False
    
    In [7]: match(phrase2)
    Out[7]: True
    

    The problem is that we find substrings:

    In [8]: phrase3 = 'bla bla word1 bla word2 bla word7 word6, word4 word3failed'
    
    In [9]: match(phrase3)
    Out[9]: True
    

    And I fixed this way:

    In [22]: import re
    In [25]: tokenize_words = re.compile(r'\w+')
    In [30]: def match(phrase):
       ....:     n_matches = 0
       ....:     phrase_words = tokenize_words.findall(phrase)
       ....:     for w in words:
       ....:         if w in phrase_words:
       ....:             n_matches += 1
       ....:     return n_matches == 6
       ....: 
    
    In [31]: match(phrase2)
    Out[31]: True
    
    In [32]: match(phrase3)
    Out[32]: False
    
    In [33]: match(phrase1)
    Out[33]: False
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm importing some data from a CSV file, and numbers that are larger than
When importing numbers from a csv file, I need to convert them to floats
When importing or exporting Databases using Taps in heroku , is it necessary that
I am importing a list from an outside document, and inputing that list into
I wanna stop the reading of my text input file when the word synonyms
I've ran across several questions and articles saying that dictionary implementation in java is
What I want to achieve: I have an online dictionary which works quite fine
I have string on the format $0Option one$1$Option two$2$Option three (etc) that I want
edit: Thanks Jason, the fact that it was a dictionary isn't that important. I
I have a dictionary that I normally access with a key, so I need

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.