Re: python2.4 generator expression > python2.3 list expression

2005-02-22 Thread Dan Sommers
On 22 Feb 2005 09:14:50 GMT, Duncan Booth <[EMAIL PROTECTED]> wrote: > Here's yet another way to achieve the same results. This version doesn't > iterate over any bits at all: import operator parity = [ False ] for i in range(7): > parity += map(operator.not_, parity) Ver

Re: python2.4 generator expression > python2.3 list expression

2005-02-22 Thread Duncan Booth
Dan Sommers wrote: >> Seems to work, is there a better way to do this? > > for c in range( 128 ): > even_odd = 0 > print '%3d' % c, > while c: > c &= c - 1 > even_odd = not even_odd > print int( even_odd ) > > Okay, so your inner loop is only counting to 8, but IM

Re: python2.4 generator expression > python2.3 list expression

2005-02-22 Thread TZOTZIOY
On Mon, 21 Feb 2005 10:55:05 -0800, rumours say that Bryan <[EMAIL PROTECTED]> might have written: [I] is to reset the rightmost (less significant) '1' bit of a number (ie change it to '0'). [bryan] >>>i tried c &= c - 1 but i'm not getting the least significant or >>>rightmost bit reset

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Terry Reedy
"Christos TZOTZIOY Georgiou" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers > <[EMAIL PROTECTED]> >>for c in range( 128 ): >>even_odd = 0 >>print '%3d' % c, >>while c: >>c &= c - 1 >>even_odd =

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Bryan
Duncan Booth wrote: Bryan wrote: is to reset the rightmost (less significant) '1' bit of a number (ie change it to '0'). i tried c &= c - 1 but i'm not getting the least significant or rightmost bit reset to zero. am i misunderstanding something? 2 & 1 # 2 = 0x10; reset right most would be 0x10

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Brian Beck
Duncan Booth wrote: The difference between the original "reset the rightmost '1' bit", and your interpretation: "reset the rightmost bit" is the "'1'". The rightmost bit that is set is reset. So 0x10 -> 0, and 0x1010 -> 0x1000. If you want to extract the least significant set bit from a number 'x

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Duncan Booth
Bryan wrote: >> is to reset the rightmost (less significant) '1' bit of a number (ie >> change it to '0'). > > i tried c &= c - 1 but i'm not getting the least significant or > rightmost bit reset to zero. am i misunderstanding something? > > >>> 2 & 1 # 2 = 0x10; reset right most would be 0x1

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Bryan
Christos TZOTZIOY Georgiou wrote: On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <[EMAIL PROTECTED]> might have written: [snip: snacktime posts code to count bits] Seems to work, is there a better way to do this? [Dan] for c in range( 128 ): even_odd = 0 print '%3d' % c, while

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread TZOTZIOY
On 21 Feb 2005 06:48:19 -0500, rumours say that Dan Sommers <[EMAIL PROTECTED]> might have written: [snip: snacktime posts code to count bits] >> Seems to work, is there a better way to do this? [Dan] >for c in range( 128 ): >even_odd = 0 >print '%3d' % c, >while c: >c &= c -

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Dan Sommers
On Sun, 20 Feb 2005 20:56:52 -0800, snacktime <[EMAIL PROTECTED]> wrote: > I need to convert a generator expression to a list expression so it > will work under python 2.3. > I rewrote this: > for c in range(128): > even_odd = (sum(bool(c & 1< As this: > for c in range(128): > bo = [bool(c

Re: python2.4 generator expression > python2.3 list expression

2005-02-21 Thread Peter Otten
snacktime wrote: > I need to convert a generator expression to a list expression so it > will work under python 2.3. > > I rewrote this: > > for c in range(128): > even_odd = (sum(bool(c & 1< > As this: > > for c in range(128): > bo = [bool(c & 1< even_odd = sum(bo) & 1 > > > Seems to

Re: python2.4 generator expression > python2.3 list expression

2005-02-20 Thread Michael Hoffman
snacktime wrote: I need to convert a generator expression to a list expression so it will work under python 2.3. I rewrote this: for c in range(128): even_odd = (sum(bool(c & 1< As this: for c in range(128): bo = [bool(c & 1< Seems to work, is there a better way to do this? If you want to keep

Re: python2.4 generator expression > python2.3 list expression

2005-02-20 Thread Steven Bethard
snacktime wrote: I need to convert a generator expression to a list expression so it will work under python 2.3. I rewrote this: for c in range(128): even_odd = (sum(bool(c & 1< As this: for c in range(128): bo = [bool(c & 1< Seems to work, is there a better way to do this? Well, if you were ha

python2.4 generator expression > python2.3 list expression

2005-02-20 Thread snacktime
I need to convert a generator expression to a list expression so it will work under python 2.3. I rewrote this: for c in range(128): even_odd = (sum(bool(c & 1