Q: python program debugging product of adjacent numbers I am currently working on project Euler question 8, which asks to find the largest product of 13 adjacent numbers in a 1000 digit long number. I imported the numpy prod function to compute products. It seems to work without the while loop but with the while loop it gives out a weird error message. can someone please explain where I'm going wrong with this?
Code:
from numpy import prod

z=\
73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
242190226710556263211111093705442175069416589604080
7198403850962455444362981230987879927244284909188
845801561660979191338754992005240636899125607176060
5886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450

b=[int(i) for i in str(z)]
x=0
i=0

while i <=1000-13:

   if prod(b[i:i+13])>x:
        x=prod(b[i:i+13])
   else:
        pass

print(x)

and here is my error output:                                  
Traceback (most recent call last):
File "/usr/lib/python3/dist-packages/numpy/core/fromnumeric.py", line 2336, in prod
prod = a.prod
AttributeError: 'list' object has no attribute 'prod'


A: You could start by converting the multiline string z into a list of digits through a list comprehension and the built-in function int():
z = """73167176531330624919225119674426574742355349194934
96983520312774506326239578318016984801869478851843
85861560789112949495459501737958331952853208805511
12540698747158523863050715693290963295227443043557
66896648950445244523161731856403098711121722383113
62229893423380308135336276614282806444486645238749
30358907296290491560440772390713810515859307960866
70172427121883998797908792274921901699720888093776
65727333001053367881220235421809751254540594752243
52584907711670556013604839586446706324415722155397
53697817977846174064955149290862569321978468622482
83972241375657056057490261407972968652414535100474
82166370484403199890008895243450658541227588666881
16427171479924442928230863465674813919123162824586
17866458359124566529476545682848912883142607690042
242190226710556263211111093705442175069416589604080
7198403850962455444362981230987879927244284909188
845801561660979191338754992005240636899125607176060
5886116467109405077541002256983155200055935729725
71636269561882670428252483600823257530420752963450"""

digits = [int(num) for num in z.replace('\n', '')]

Notice the line breaks have been removed from the original string by invoking z.replace('\n', '').
Then you could use the function operator.mul() to get the job done in just one line of code:
from operator import mul
x = max(reduce(mul, digits[i:i+13]) for i in range(len(digits) - 12))

Python 3 users will need to add the sentence from functools import reduce since in the latest versions of the language reduce() is no longer a built-in function.
Demo:
In [304]: digits
Out[304]: 
[7, 
 3, 
 1,
 6,
 ...
 3,
 4,
 5,
 0]

In [305]: x
Out[305]: 23514624000L

