Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #62893 > unrolled thread

Dictionary

Started byBischoop <martin@jakis.adres.em>
First post2013-12-30 18:38 +0000
Last post2014-01-09 11:21 +1100
Articles 8 — 5 participants

Back to article view | Back to comp.lang.python


Contents

  Dictionary Bischoop <martin@jakis.adres.em> - 2013-12-30 18:38 +0000
    Re: Dictionary Walter Hurry <walterhurry@gmail.com> - 2013-12-30 18:56 +0000
      Re: Dictionary Bischoop <martin@jakis.adres.em> - 2014-01-08 19:00 +0000
        Re: Dictionary wxjmfauth@gmail.com - 2014-01-09 00:31 -0800
    Re: Dictionary Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-30 15:00 -0500
      Re: Dictionary Bischoop <martin@jakis.adres.em> - 2014-01-08 18:51 +0000
        Re: Dictionary Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-08 19:13 -0500
        Re: Dictionary Chris Angelico <rosuav@gmail.com> - 2014-01-09 11:21 +1100

#62893 — Dictionary

FromBischoop <martin@jakis.adres.em>
Date2013-12-30 18:38 +0000
SubjectDictionary
Message-ID<x4jwu.3413$Bs5.1921@fx09.am4>
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

[toc] | [next] | [standalone]


#62894

FromWalter Hurry <walterhurry@gmail.com>
Date2013-12-30 18:56 +0000
Message-ID<l9sfl2$92u$1@news.albasani.net>
In reply to#62893
On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop 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 
you.

[toc] | [prev] | [next] | [standalone]


#63509

FromBischoop <martin@jakis.adres.em>
Date2014-01-08 19:00 +0000
Message-ID<Tehzu.22168$q32.2875@fx07.am4>
In reply to#62894
Walter Hurry wrote:

> On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop 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
> 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.

[toc] | [prev] | [next] | [standalone]


#63582

Fromwxjmfauth@gmail.com
Date2014-01-09 00:31 -0800
Message-ID<1a719495-c63a-4109-89d7-ca5118f5ccdc@googlegroups.com>
In reply to#63509
Le mercredi 8 janvier 2014 20:00:02 UTC+1, Bischoop a écrit :
> Walter Hurry wrote:
> 
> 
> 
> > On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop 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
> 
> > 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.

>>> # 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
>>>

[toc] | [prev] | [next] | [standalone]


#62899

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2013-12-30 15:00 -0500
Message-ID<mailman.4725.1388433616.18130.python-list@python.org>
In reply to#62893
On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop <martin@jakis.adres.em>
declaimed the following:

>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
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#63507

FromBischoop <martin@jakis.adres.em>
Date2014-01-08 18:51 +0000
Message-ID<P6hzu.2028$Wn7.1602@fx20.am4>
In reply to#62899
Dennis Lee Bieber wrote:

> On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop <martin@jakis.adres.em>
> declaimed the following:
> 
>>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.

[toc] | [prev] | [next] | [standalone]


#63543

FromDennis Lee Bieber <wlfraed@ix.netcom.com>
Date2014-01-08 19:13 -0500
Message-ID<mailman.5214.1389226408.18130.python-list@python.org>
In reply to#63507
On Wed, 08 Jan 2014 18:51:26 +0000, Bischoop <martin@jakis.adres.em>
declaimed the following:

>Dennis Lee Bieber wrote:
>
>> On Mon, 30 Dec 2013 18:38:20 +0000, Bischoop <martin@jakis.adres.em>
>> declaimed the following:
>> 
>>>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
-- 
	Wulfraed                 Dennis Lee Bieber         AF6VN
    wlfraed@ix.netcom.com    HTTP://wlfraed.home.netcom.com/

[toc] | [prev] | [next] | [standalone]


#63546

FromChris Angelico <rosuav@gmail.com>
Date2014-01-09 11:21 +1100
Message-ID<mailman.5217.1389226906.18130.python-list@python.org>
In reply to#63507
On Thu, Jan 9, 2014 at 11:13 AM, Dennis Lee Bieber
<wlfraed@ix.netcom.com> wrote:
>         #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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web