a couple of things I don't understand wrt lists
darnold
darnold992000 at yahoo.com
Wed Apr 17 09:43:42 EDT 2013
On Apr 17, 5:25 am, aaB <mecagonoisic... at gmail.com> wrote:
>
> - the "complement" thing:
> I haven't yet tried to reproduce this, but I will, and I will post back if I see
> this happening again, this time with a real log of python's interactive console,
> or a complete script which people can use.
>
That was happening when you incorrectly used bit as an index back into
bitpattern.
When you do that, the behavior actually changes depending on the value
of bitpattern:
a bitpattern that starts with [1, 0, ...] will yield its complement:
>>> bitpattern = [1, 0, 0, 1, 1, 0, 1]
>>> for bit in bitpattern:
print 'bitpattern[%s] : %s' % (bit, bitpattern[bit])
bitpattern[1] : 0
bitpattern[0] : 1
bitpattern[0] : 1
bitpattern[1] : 0
bitpattern[1] : 0
bitpattern[0] : 1
bitpattern[1] : 0
>>>
while a bitpattern that starts with [0, 1, ...] will yield the
expected results:
>>> bitpattern = [0, 1, 0, 1, 1, 0, 1]
>>> for bit in bitpattern:
print 'bitpattern[%s] : %s' % (bit, bitpattern[bit])
bitpattern[0] : 0
bitpattern[1] : 1
bitpattern[0] : 0
bitpattern[1] : 1
bitpattern[1] : 1
bitpattern[0] : 0
bitpattern[1] : 1
>>>
HTH,
Don
More information about the Python-list
mailing list