recursive method not reaching base case

2005-03-23 Thread possibilitybox
i was working on implementing the original supermemo algorithm (see
http://www.supermemo.com/english/ol/sm2.htm for a description of it) in
a class, and i'd just finished up the first draft.  it works for
repetitions one and two, but on repetition three (you must manually
increment item.reps.) or higher it recurses until it reaches the limit.
 can someone point out what i'm doing wrong here?

here's the code:
class item:
def __init__(self, key, value):
self.key = key
self.value = value
self.reps = 1
self.ef = 2.5
def interval(self):
if(self.reps==1):
return 2
if(self.reps==2):
return 6
return (self.interval() - 1) * self.ef

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: recursive method not reaching base case

2005-03-23 Thread possibilitybox
so obvious!  thank you for helping me there.  i knew it was simple, i
just couldn't catch it.

-- 
http://mail.python.org/mailman/listinfo/python-list


large dictionary creation takes a LOT of time.

2005-04-28 Thread possibilitybox
this code here:


def wordcount(lines):
for i in range(len(lines)/8):
words = lines[i].split(" ")
if not locals().has_key("frequency"):
frequency = {}
for word in words:
if frequency.has_key(word):
frequency[word] += 1
else:
frequency[word] = 1
return frequency
wordcount(lines)

is taking over six minutes to run on a two megabyte text file.  i
realize that's a big text file, a really big one (it's actually the
full text of don quixote.).  i'm trying to figure out how.  is there a
better way for me to do a frequency count of all the words in the text?
 it seems to me like this should scale linearly, but perhaps it isn't?
i don't know much about algorithmic complexity.  if someone could give
a breakdown of this functions complexity as well i'd be much obliged.

lines is expected to be a list of lines as provided by file.readline()

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: large dictionary creation takes a LOT of time.

2005-04-29 Thread possibilitybox
oh, right, i did only one eighth to check and see if it was scaling
near linearly, as i couldn't even run profiling without python dying.

i have 400mb ram and 2ghz processor, on freebsd, so it shouldn't be
performance.  i'll try your suggestions and see how it works.

-- 
http://mail.python.org/mailman/listinfo/python-list


Finding Upper-case characters in regexps, unicode friendly.

2006-05-24 Thread possibilitybox
I'm trying to make a unicode friendly regexp to grab sentences
reasonably reliably for as many unicode languages as possible, focusing
on european languages first, hence it'd be useful to be able to refer
to any uppercase unicode character instead of just the typical [A-Z],
which doesn't include, for example É.   Is there a way to do this, or
do I have to stick with using the isupper method of the string class?

-- 
http://mail.python.org/mailman/listinfo/python-list


Finding Upper-case characters in regexps, unicode friendly.

2006-05-24 Thread possibilitybox
I'm trying to make a unicode friendly regexp to grab sentences
reasonably reliably for as many unicode languages as possible, focusing
on european languages first, hence it'd be useful to be able to refer
to any uppercase unicode character instead of just the typical [A-Z],
which doesn't include, for example É.   Is there a way to do this, or
do I have to stick with using the isupper method of the string class?

-- 
http://mail.python.org/mailman/listinfo/python-list