On Thu, 14 Mar 2013, Steven D'Aprano wrote:
If you have some unknown, arbitrary iterable that doesn't support len(),
then you can use the sum() trick:
it = some_unknown_iterable()
sum(1 for x in it)
Yes, of course you are correct. This was my intention, but I chose an
especially poorly contri
On 14/03/13 12:13, David Knupp wrote:
FWIW, if you're working with very large lists, but don't need to create the
full list in memory, then a generator expression is usually preferred. To get
the number of items a generator would return, you can use sum() like this:
gen = (n for n in xrange(
On 14/03/13 08:12, Abhishek Pratap wrote:
import numpy as np
count = 0
[ count += 1 for num in np.random.random_integers(1,100,20) if num > 20]
File "", line 2
[ count += 1 for num in np.random.random_integers(1,100,20) if num > 20]
^
SyntaxError: invalid syntax
[...]
I
On 14/03/2013 01:13, David Knupp wrote:
On Wed, 13 Mar 2013, Oscar Benjamin wrote:
(it's not actually a generator by the way)
As Oscar points out, you're not working with a generator expression. The
syntactical difference between a list comprehension and a generator
expression is subtle. List
On Wed, 13 Mar 2013, Oscar Benjamin wrote:
(it's not actually a generator by the way)
As Oscar points out, you're not working with a generator expression. The
syntactical difference between a list comprehension and a generator
expression is subtle. List comprehensions use square brackets, but
On 13 March 2013 21:12, Abhishek Pratap wrote:
> On Wed, Mar 13, 2013 at 2:02 PM, Oscar Benjamin
> wrote:
>> On 13 March 2013 19:50, Abhishek Pratap wrote:
>>> Hey Guys
>>>
>>> I might be missing something obvious here.
>>>
>>>
>>> import numpy as np
>>>
>>> count = 0
>>> [ count += 1 for num in
On Wed, Mar 13, 2013 at 2:08 PM, Dave Angel wrote:
> On 03/13/2013 03:50 PM, Abhishek Pratap wrote:
>>
>> 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 "
On Wed, Mar 13, 2013 at 2:02 PM, Oscar Benjamin
wrote:
> On 13 March 2013 19:50, Abhishek Pratap wrote:
>> 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
On 03/13/2013 03:50 PM, Abhishek Pratap wrote:
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 "", line 2
[ count += 1 for num in np.random.random_integers(1,100,20) if num >
On 13 March 2013 19:50, Abhishek Pratap wrote:
> 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 "", line 2
> [ count += 1 for num in np.random.random_integers(1,
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 "", line 2
[ count += 1 for num in np.random.random_integers(1,100,20) if num > 20]
^
SyntaxError: invalid syntax
A
11 matches
Mail list logo