Re: A bit weird dictionary behavior

2008-09-24 Thread Lawrence D'Oliveiro
In message <[EMAIL PROTECTED]>, Terry Reedy wrote: > From this viewpoint, objecters would instead have to argue that it is > wrong to have such implicit calls and that programmers should have to > put them in explicitly. But then again, you want to avoid unexpected restrictions like in Java, whe

Re: A bit weird dictionary behavior

2008-09-23 Thread Bruno Desthuilliers
Carl Banks a écrit : On Sep 22, 3:43 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] a écrit : Pekka Laukkanen: but it still doesn't feel exactly right. Would it be worth submitting a bug? It feels wrong because it is. In a tidier language (Pascal, Java, etc) a boolean a

Re: A bit weird dictionary behavior

2008-09-22 Thread bearophileHUGS
Steven D'Aprano: >For many iterables, the amount of memory is not excessive and the increase in >readability of len() is to be preferred over the side-effect of sum(1 for...).< With side-effects do you mean the possibility of exhausting a lazy iterable? The readability difference is little, and

Re: A bit weird dictionary behavior

2008-09-22 Thread Terry Reedy
Grzegorz Staniak wrote: On 22.09.2008, Carl Banks <[EMAIL PROTECTED]> wroted: Some would argue (and some did by the time Python grew a 'bool' type) that what is wrong is to have a bool type in a language that already have a wider definition of the truth value of an expression... And some woul

Re: A bit weird dictionary behavior

2008-09-22 Thread Steven D'Aprano
On Mon, 22 Sep 2008 07:35:50 -0700, bearophileHUGS wrote: > Tino Wildenhain: > >> Wouldn't >> len([x for x in iterable if x==y]) >> or even shorter: >> iterable.count(y) >> not work and read better anyway? > > The first version creates an actual list just to take its length, think > about how mu

Re: A bit weird dictionary behavior

2008-09-22 Thread Grzegorz Staniak
On 22.09.2008, Carl Banks <[EMAIL PROTECTED]> wroted: >> >> but it still doesn't feel exactly right. Would it be worth submitting a >> >> bug? >> >> > It feels wrong because it is. In a tidier language (Pascal, Java, etc) >> > a boolean and an integer must be different types. >> >> Some would arg

Re: A bit weird dictionary behavior

2008-09-22 Thread Carl Banks
On Sep 22, 3:43 pm, Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > [EMAIL PROTECTED] a écrit : > > > Pekka Laukkanen: > >> but it still doesn't feel exactly right. Would it be worth submitting a > >> bug? > > > It feels wrong because it is. In a tidier language (Pascal, Java, etc) > > a boolean

Re: A bit weird dictionary behavior

2008-09-22 Thread Bruno Desthuilliers
[EMAIL PROTECTED] a écrit : Pekka Laukkanen: but it still doesn't feel exactly right. Would it be worth submitting a bug? It feels wrong because it is. In a tidier language (Pascal, Java, etc) a boolean and an integer must be different types. Some would argue (and some did by the time Python

Re: A bit weird dictionary behavior

2008-09-22 Thread Tino Wildenhain
Hi, [EMAIL PROTECTED] wrote: Tino Wildenhain: Wouldn't len([x for x in iterable if x==y]) or even shorter: iterable.count(y) not work and read better anyway? The first version creates an actual list just to take its length, think about how much memory it may use. yes it seems len() does no

Re: A bit weird dictionary behavior

2008-09-22 Thread bearophileHUGS
Tino Wildenhain: > Wouldn't > len([x for x in iterable if x==y]) > or even shorter: > iterable.count(y) > not work and read better anyway? The first version creates an actual list just to take its length, think about how much memory it may use. The second version requires the 'iterable' object to

Re: A bit weird dictionary behavior

2008-09-22 Thread Tino Wildenhain
Hi, [EMAIL PROTECTED] wrote: Pekka Laukkanen: ... On the other hand it has some little practical advantages, you can do: sum(x == y for x in iterable) That also equals to a more tidy: sum(1 for x in iterable if x == y) Wouldn't len([x for x in iterable if x==y]) or even shorter: iterable.

Re: A bit weird dictionary behavior

2008-09-22 Thread bearophileHUGS
Pekka Laukkanen: > but it still doesn't feel exactly right. Would it be worth submitting a bug? It feels wrong because it is. In a tidier language (Pascal, Java, etc) a boolean and an integer must be different types. Keeping booleans and integers separated may avoid some bugs too (I don't know how

Re: A bit weird dictionary behavior

2008-09-22 Thread Arnaud Delobelle
On 22 Sep, 10:25, "Pekka Laukkanen" <[EMAIL PROTECTED]> wrote: > Hello, > > just noticed this: > > Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) > [GCC 4.0.1 (Apple Inc. build 5465)] on darwin > Type "help", "copyright", "credits" or "license" for more information.>>> {1: > 2} > {1: 2} > >>> {T

A bit weird dictionary behavior

2008-09-22 Thread Pekka Laukkanen
Hello, just noticed this: Python 2.5.1 (r251:54863, Jan 17 2008, 19:35:17) [GCC 4.0.1 (Apple Inc. build 5465)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> {1: 2} {1: 2} >>> {True: False} {True: False} >>> {1: 2, True: False} {1: False} This must be becaus