[Tutor] about little function

Abdirizak abdi a_abdi406@yahoo.com
Sat Jun 7 12:55:29 2003


--0-1166050707-1055004827=:58558
Content-Type: text/plain; charset=us-ascii

Hi,
I was working on a program that combines a list of values such as this list List = [1,2,3,5,6...] and it also does some computation such as the folowing in the function :
 
def combine(list_probabilities):
    """ it combines the probabilty of list items"""
    p1 = 1.0
    p2 = 1.0
    #print list_probabilities
    for i in list_probabilities:
        #print i
        p1 = p1 * i
        p2 = p2 * (1.0 - i)
    result = p1 / (p1 + P2)
    return result
 
Problem: when I try to run the program it gives me type error such as the following :
 
Traceback (most recent call last):
  File "classifier.py", line 202, in ?
    sw.isSpam(text)
  File "classifier.py", line 140, in isSpam
    score = combine(list)
  File "classifier.py", line 36, in combine
    p1 = p1 * i
TypeError: unsupported operand type(s) for *: 'float' and 'list'
 
can anyone help me why it is giving me this error, when I try on python interactive it works but in the program it doesn't.
 
thanks in advance


---------------------------------
Do you Yahoo!?
Free online calendar with sync to Outlook(TM).
--0-1166050707-1055004827=:58558
Content-Type: text/html; charset=us-ascii

<DIV>Hi,</DIV>
<DIV>I was working on a program that combines a list of values such as this list List = [1,2,3,5,6...] and it also&nbsp;does some computation such as the folowing in the function :</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#7f003f>def combine(list_probabilities):<BR>&nbsp;&nbsp;&nbsp; """ it combines the probabilty of list items"""<BR>&nbsp;&nbsp;&nbsp; p1 = 1.0<BR>&nbsp;&nbsp;&nbsp; p2 = 1.0<BR>&nbsp;&nbsp;&nbsp; #print list_probabilities<BR>&nbsp;&nbsp;&nbsp; for i in list_probabilities:<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #print i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p1 = p1 * i<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p2 = p2 * (1.0 - i)</FONT></DIV>
<DIV><FONT color=#7f003f>&nbsp;&nbsp;&nbsp; result = p1 / (p1 + P2)<BR>&nbsp;&nbsp;&nbsp; return result</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>Problem: when I try to run the program it gives me type error such as the following :</DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT color=#ff409f>Traceback (most recent call last):<BR>&nbsp; File "classifier.py", line 202, in ?<BR>&nbsp;&nbsp;&nbsp; sw.isSpam(text)<BR>&nbsp; File "classifier.py", line 140, in isSpam<BR>&nbsp;&nbsp;&nbsp; score = combine(list)<BR>&nbsp; File "classifier.py", line 36, in combine<BR>&nbsp;&nbsp;&nbsp; p1 = p1 * i<BR>TypeError: unsupported operand type(s) for *: 'float' and 'list'</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV>can anyone help me why it is giving me this error, when I try on python interactive it works but in the program it doesn't.</DIV>
<DIV>&nbsp;</DIV>
<DIV>thanks in advance</DIV><p><hr SIZE=1>
Do you Yahoo!?<br>
Free <a href="http://us.rd.yahoo.com/mail_us/tag/*http://calendar.yahoo.com">online calendar</a> with sync to Outlook(TM).
--0-1166050707-1055004827=:58558--