Dictionary

B

Bischoop

I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o
 
D

Dennis Lee Bieber

I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o

Vague requirement...

Do you need:
1 any word containing any single letter
2 any word containing all supplied letters (is there a limit on how many
letters?)
3 any word containing the supplied letters in the entered order, but not
necessarily adjacent to each other
4 any word containing the supplied letters in adjacent sequence
5 any word that begins with the supplied sequence of letters
 
B

Bischoop

Dennis said:
I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o

Vague requirement...

Do you need:
1 any word containing any single letter
2 any word containing all supplied letters (is there a limit on how many
letters?)
3 any word containing the supplied letters in the entered order, but not
necessarily adjacent to each other
4 any word containing the supplied letters in adjacent sequence
5 any word that begins with the supplied sequence of letters

1.yes
2. Any combination with supplied letters. It would be great if possible that
I could set also the combination for example: show me all words with: l,x
3. the order doesn't matter
4. doesnt matter
5 doesnt matter.
 
B

Bischoop

Walter said:
I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o

Well, what have you tried so far, and what result did you get?

The incredibly helpful people here will provide advice, guidance and
pointers, but it won't help you at all if they just do your homework for
you.


Honestly Im newbie in Python, years ago (10 already) I wrote simply program
something like a TEST: Capitals of Countries. You could learn the capitals
of some countries, and then you could try to solve a test. I know it's seems
so simply for you guys but I was quite pride of myself :)

Now because of free time I took my book which I used years ago about python
and try to learn it again, and as motivation I try to write the program I
described above just to give me a kick :), however got no idea how to start
it, I meand there is so many moduls (import this, import that), I know how
to open, read file etc. Just stuck with that, got no clue what and how use
this that what I need to seek the words from the files if I need a words
with letters I want.
 
D

Dennis Lee Bieber

Dennis said:
I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o

Vague requirement...

Do you need:
1 any word containing any single letter
2 any word containing all supplied letters (is there a limit on how many
letters?)
3 any word containing the supplied letters in the entered order, but not
necessarily adjacent to each other
4 any word containing the supplied letters in adjacent sequence
5 any word that begins with the supplied sequence of letters

1.yes
2. Any combination with supplied letters. It would be great if possible that
I could set also the combination for example: show me all words with: l,x
3. the order doesn't matter
4. doesnt matter
5 doesnt matter.

No doubt someone will suggest using a regular expression, but since
I've never used the re/regex modules I can't give the full work...
PseudoCode may be something like

fwin = open("dictionary.txt", "r")
haystack = fwin.read().lower().split("\n")
fwin.close()

while True:
letters = input("Enter letters> ")
if not letters: break
#generate search re expression representing
# .* any character/multiple -- leading
# [l|e|t|t|e|r] match any of the letters supplied
# .* any character/multiple -- trailing
needle = ".*[" + "|".join(list(letters.lower())) + "].*"
#do a regular expression search of haystack using needle as
#search condition
# print matches

----

The slower non-re version might be something like

fwin = open("dictionary.text", "r")
haystack = fwin.read().lower().split("\n")
fwin.close()

while True:
letters = input("Enter letters> ").lower()
if not letters: break
for word in haystack:
for letter in letters:
if letter in word:
print word
break
 
C

Chris Angelico

#generate search re expression representing
# .* any character/multiple -- leading
# [l|e|t|t|e|r] match any of the letters supplied
# .* any character/multiple -- trailing
needle = ".*[" + "|".join(list(letters.lower())) + "].*"

I don't think this will do what you think it will. It'll match
anything that has any one of the supplied letters (or a pipe; it's a
character class, so the pipe has no significance and is simply part of
the class). I'm not sure a regex is the best thing here; but what you
could do is sort the letters and sort the letters in the words:

pat = ".*".join(sorted(letters.lower()))
for word in open("/usr/share/dict/words"): # Ought to use with
if re.search(pat, ''.join(sorted(word))): print(word)

ChrisA
 
W

wxjmfauth

Le mercredi 8 janvier 2014 20:00:02 UTC+1, Bischoop a écrit :
Walter Hurry wrote:


I have a txt file with some words, and need simply program that will
print me words containing provided letters.

For example:
Type the letters:
(I type: g,m,o)
open the dictionary.txt
check words containing:g,m,o in dictionary.txt
if there are words containing: ["g", "m", "o" ]
print words with g,m,o
Well, what have you tried so far, and what result did you get?
The incredibly helpful people here will provide advice, guidance and
pointers, but it won't help you at all if they just do your homework for





Honestly Im newbie in Python, years ago (10 already) I wrote simply program

something like a TEST: Capitals of Countries. You could learn the capitals

of some countries, and then you could try to solve a test. I know it's seems

so simply for you guys but I was quite pride of myself :)



Now because of free time I took my book which I used years ago about python

and try to learn it again, and as motivation I try to write the program I

described above just to give me a kick :), however got no idea how to start

it, I meand there is so many moduls (import this, import that), I know how

to open, read file etc. Just stuck with that, got no clue what and how use

this that what I need to seek the words from the files if I need a words

with letters I want.
# a starting point
lettres = set('üœŸ')
Wörter = ['abcüœŸb', 'aüꜟ','üœŸzzz', 'üœzz', 'Strauẞ', '', 'nul']
for word in Wörter:
.... tmp = set(word)
.... print('{:10} : {}'.format(word, lettres.issubset(tmp)))
....
abcüœŸb : True
aüꜟ : True
üœŸzzz : True
üœzz : False
Strauẞ : False
: False
nul : False
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,163
Latest member
Sasha15427
Top