[Tutor] increment a counter inside generator

Abhishek Pratap abhishek.vit at gmail.com
Wed Mar 13 20:50:28 CET 2013


Hey Guys

I might be missing something obvious here.


import numpy as np

count = 0
[ count += 1 for num in np.random.random_integers(1,100,20) if num > 20]

 File "<ipython-input-45-0ba0e51b7644>", line 2
    [ count += 1 for num in np.random.random_integers(1,100,20) if num > 20]
             ^
SyntaxError: invalid syntax


Also tried


More information about the Tutor mailing list