Re: anagram finder / dict mapping question

2008-05-10 Thread Kam-Hung Soh
On Sat, 10 May 2008 18:06:17 +1000, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: "Kam-Hung Soh" <[EMAIL PROTECTED]> writes: On Sat, 10 May 2008 07:19:38 +1000, <[EMAIL PROTECTED]> wrote: > What would be the best method to print the top results, the one's that > had the highest amount of a

Re: anagram finder / dict mapping question

2008-05-10 Thread Arnaud Delobelle
"Kam-Hung Soh" <[EMAIL PROTECTED]> writes: > On Sat, 10 May 2008 07:19:38 +1000, <[EMAIL PROTECTED]> wrote: > >>> > What would be the best method to print the top results, the one's that >>> > had the highest amount of anagrams?? Create a new histogram dict? >>> >>> You can use the max() function

Re: anagram finder / dict mapping question

2008-05-10 Thread George Sakkis
On May 9, 11:19 pm, dave <[EMAIL PROTECTED]> wrote: > On 2008-05-09 18:53:19 -0600, George Sakkis <[EMAIL PROTECTED]> said: > > > > > On May 9, 5:19 pm, [EMAIL PROTECTED] wrote: > What would be the best method to print the top results, the one's that > > had the highest amount of anagrams

Re: anagram finder / dict mapping question

2008-05-09 Thread dave
On 2008-05-09 18:53:19 -0600, George Sakkis <[EMAIL PROTECTED]> said: On May 9, 5:19 pm, [EMAIL PROTECTED] wrote: What would be the best method to print the top results, the one's that had the highest amount of anagrams??  Create a new histogram dict? You can use the max() function to fin

Re: anagram finder / dict mapping question

2008-05-09 Thread George Sakkis
On May 9, 5:19 pm, [EMAIL PROTECTED] wrote: > > > What would be the best method to print the top results, the one's that > > > had the highest amount of anagrams??  Create a new histogram dict? > > > You can use the max() function to find the biggest list of anagrams: > > > top_results = max(anagra

Re: anagram finder / dict mapping question

2008-05-09 Thread Kam-Hung Soh
On Sat, 10 May 2008 07:19:38 +1000, <[EMAIL PROTECTED]> wrote: > What would be the best method to print the top results, the one's that > had the highest amount of anagrams?? Create a new histogram dict? You can use the max() function to find the biggest list of anagrams: top_results = max(an

Re: anagram finder / dict mapping question

2008-05-09 Thread umpsumps
> > What would be the best method to print the top results, the one's that > > had the highest amount of anagrams?? Create a new histogram dict? > > You can use the max() function to find the biggest list of anagrams: > > top_results = max(anagrams.itervalues(), key=len) > > -- > Arnaud That is t

Re: anagram finder / dict mapping question

2008-05-09 Thread Arnaud Delobelle
[EMAIL PROTECTED] writes: > On May 9, 1:45 am, [EMAIL PROTECTED] wrote: >> >>> key = ''.join(sorted(word)) >> >> I tend to strip and lower the word as well, otherwise "Hello" and >> "hello" do not compare...depends on what you want though! >> Plus you might get a lot of "word\n" as keys... >> >> M

Re: anagram finder / dict mapping question

2008-05-09 Thread umpsumps
On May 9, 1:45 am, [EMAIL PROTECTED] wrote: > >>> key = ''.join(sorted(word)) > > I tend to strip and lower the word as well, otherwise "Hello" and > "hello" do not compare...depends on what you want though! > Plus you might get a lot of "word\n" as keys... > > My technique is the this way > > def

Re: anagram finder / dict mapping question

2008-05-09 Thread cokofreedom
>>> key = ''.join(sorted(word)) I tend to strip and lower the word as well, otherwise "Hello" and "hello" do not compare...depends on what you want though! Plus you might get a lot of "word\n" as keys... My technique is the this way def anagram_finder(words): anagrams = {} for word in wo

Re: anagram finder / dict mapping question

2008-05-08 Thread Arnaud Delobelle
"Kam-Hung Soh" <[EMAIL PROTECTED]> writes: > I avoid creating a temporary variable if it's only used once > immediately, so I would have written: > > newtlist = ''.join(sorted(list(line))) Or ''.join(sorted(line)) as sorted() works with any iterable. -- Arnaud -- http://mail.python.org/mailma

Re: anagram finder / dict mapping question

2008-05-08 Thread Jerry Hill
On Thu, May 8, 2008 at 7:52 PM, dave <[EMAIL PROTECTED]> wrote: > I got it! Thanks for all your help!!! Please tell me what you think: Here's yet another version of the same thing, using defaultdicts and sets. This way we don't have to test for membership in either the dictionary or the co

Re: anagram finder / dict mapping question

2008-05-08 Thread Kam-Hung Soh
On Fri, 09 May 2008 09:52:53 +1000, dave <[EMAIL PROTECTED]> wrote: I got it! Thanks for all your help!!! Please tell me what you think: def anafind(): fin = open('short.txt') #one word per line mapdic = {} #this di

Re: anagram finder / dict mapping question

2008-05-08 Thread Paul Rubin
dave <[EMAIL PROTECTED]> writes: > if newtlist not in mapdic: > mapdic[newtlist] = [line] > if line not in mapdic[newtlist]: > mapdic[newtlist].append(line) I'd use the defaultdi

Re: anagram finder / dict mapping question

2008-05-08 Thread dave
On 2008-05-07 19:25:53 -0600, "Kam-Hung Soh" <[EMAIL PROTECTED]> said: On Thu, 08 May 2008 11:02:12 +1000, dave <[EMAIL PROTECTED] t> wrote: Hi All, I wrote a program that takes a string sequence and finds all the wo rds inside a text file (one word per line) and prints them: def an

Re: anagram finder / dict mapping question

2008-05-08 Thread offby1
Been there, done that: http://polyglot-anagrams.googlecode.com/svn/trunk/python/ -- http://mail.python.org/mailman/listinfo/python-list

Re: anagram finder / dict mapping question

2008-05-08 Thread Terry Reedy
"Kam-Hung Soh" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] | On Thu, 08 May 2008 15:42:07 +1000, dave <[EMAIL PROTECTED]> | wrote: | Your code is always going to return the same list because every word is an | anagram of itself. | | Tip: Create a list for each dictionary key, the

Re: anagram finder / dict mapping question

2008-05-08 Thread Kam-Hung Soh
On Thu, 08 May 2008 15:42:07 +1000, dave <[EMAIL PROTECTED]> wrote: This is what i've came up with. My problem is that I can't get them to properly evaluate.. when comparewords() runs it finds itself... Should I have the keys of mapdict iterate over itself? Is that possible? def annaf

Re: anagram finder / dict mapping question

2008-05-07 Thread dave
This is what i've came up with. My problem is that I can't get them to properly evaluate.. when comparewords() runs it finds itself... Should I have the keys of mapdict iterate over itself? Is that possible? def annafind(): fin = open('text.txt') # file has one word per li

Re: anagram finder / dict mapping question

2008-05-07 Thread Kam-Hung Soh
On Thu, 08 May 2008 11:02:12 +1000, dave <[EMAIL PROTECTED]> wrote: Hi All, I wrote a program that takes a string sequence and finds all the words inside a text file (one word per line) and prints them: def anagfind(letters): #find anagrams of these letters fin = open('text.txt')

anagram finder / dict mapping question

2008-05-07 Thread dave
Hi All, I wrote a program that takes a string sequence and finds all the words inside a text file (one word per line) and prints them: def anagfind(letters): #find anagrams of these letters fin = open('text.txt') #one word per line file wordbox = [] #this is where