learning with python question (HtTLaPP)

2008-04-26 Thread umpsumps
Hello all, I've been trying to teach myself python from "How to Think Like a Python Programmer" and have been trying to write a script that checks 'words.txt' for parameters (letters) given. The problem that is the i can only get results for the exact sequnce of parameter 'letters'. I'll spare po

Re: learning with python question (HtTLaPP)

2008-04-26 Thread umpsumps
Eric, Thank you for helping. Is the way I wrote the function inherently wrong? What I wrote returns the sequence, however I'm trying to make the output match for the letters in the string entered, not necessarily the string sequence. For example if I search words.txt with my function for 'uzi'

Re: learning with python question (HtTLaPP)

2008-04-26 Thread umpsumps
This is what I'm stuck on. I keep doing things like: for line in fin: for ch in letters: if ch not in line: I've tried for ch in letters: for line in fin: too.. Should I use a while statement? What's the best way to compare a group of letters to a line? > This would be a m

Re: learning with python question (HtTLaPP)

2008-04-26 Thread umpsumps
ok.. I finally made something that works.. Please let me know what you think: >>> def lines(letters): fin = open('words.txt') count = 0 rescount = 0 # count the number of results results = "" # there are words that contain the letters for line in fin:

letter frequency counter / your thoughts..

2008-05-07 Thread umpsumps
Hello, Here is my code for a letter frequency counter. It seems bloated to me and any suggestions of what would be a better way (keep in my mind I'm a beginner) would be greatly appreciated.. def valsort(x): res = [] for key, value in x.items(): res.append((value,

Re: letter frequency counter / your thoughts..

2008-05-07 Thread umpsumps
That's a great suggestion Arnaud. I'll keep that in mind next time I post code. Thanks ;) On May 7, 12:27 pm, Arnaud Delobelle <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] writes: > > Hello, > > > Here is my code for a letter frequency counter. It seems bloated to > > me and any suggestions o

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