On 31/05/13 19:23, Nick Shemonsky wrote:

or maybe it'd be quicker to compare a to b through each iteration and
just keep the larger product rather than creating a giant list

You are probably right if it is a giant list.

str_num = '1234567890'
n = 5

strings = [str_num[i:i+5] for i in range(0, len(str_num)) if
len(str_num[i:i+5])==5]
integers = [int(i) for i in strings[0]]

def product(x):
     p = 1
     for n in integers:
         p*=n
     return p

You define a parameter x but don't use it?

You could use reduce here:

import operator
...
def product(intlist):
    return reduce(operator.mul, intlist)

HTH
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

_______________________________________________
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to