On Oct 28, 10:40 am, Chris Rebert wrote:
> On Tue, Oct 27, 2009 at 7:15 PM, Lambda wrote:
> > I defined a function to raise a 2x2 matrix to nth power:
>
> > def matrix_power(m, n):
> > result = m[:]
>
> Note that this only copies the *outer* list. It does NOT c
I defined a function to raise a 2x2 matrix to nth power:
def matrix_power(m, n):
result = m[:]
print result is m
for i in range(n - 1):
result[0][0] = result[0][0] * m[0][0] + result[0][1] * m[1][0]
result[0][1] = result[0][0] * m[0][1] + result[0][1] * m[1][1]
result[1][0] = re
Hi,
I'd like to define a class to use it as a dictionary key:
class dict_entry:
def __init__(self, term = "", doc_freq = 0):
self.term = term
self.doc_freq = doc_freq
def __cmp__(self, entry):
return isinstance(entry, dict_entry) and cmp(self.term,
entry.term)
def __str__(self