a couple of things I don't understand wrt lists

aaB mecagonoisician at gmail.com
Wed Apr 17 06:25:37 EDT 2013


Hello,

Thanks for all your replies, things are getting clearer.


- copy/paste vs retyping:
Several people have remarked that I had retyped instead of copy/pasting.
This is exactly what happened, the fact is I haven't figured out yet how to
enable copy/pasting from urxvt to vim.
I'll try to get this done before posting output from an interactive session.


- iterating a list:
If I understand what you've told me,

bitpattern = [1, 0, 0, 1, 1, 0, 1]
for bit in bitpattern: 
  print bit

and 

bitpattern = [1, 0, 0, 1, 1, 0, 1]
for i in range(len(bitpattern)): 
  print bitpattern[i]

are equivalent, the former being more "python" and the latter being something
like C written using python syntax.


- 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.


- list comprehension:
I wasn't at all aware of this, thanks a lot for pointing it out.
I had an other function that generated a list of cells for the CA, each cell
being randomly alive or dead.
I have rewritten it using list comprehension,

def populate(n):
  random.seed()
  return [random.randint(0,1) for i in range(n)]

which works the same as my previous, C-like, version but feels much better.

I might come back to you all but you've already given me a good push forward, so
I guess I'll be trying to use it as much as I can before asking for an other.



More information about the Python-list mailing list