Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #43752

Re: a couple of things I don't understand wrt lists

Date 2013-04-17 12:25 +0200
From aaB <mecagonoisician@gmail.com>
Subject Re: a couple of things I don't understand wrt lists
References <20130416153701.GA18377@gmail.com> <CAPTjJmqRB0eiG9peDOU+Ow_1rqq2u=xXcUduyxUm3gAhrzMjHg@mail.gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.719.1366194346.3114.python-list@python.org> (permalink)

Show all headers | View raw


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.

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: a couple of things I don't understand wrt lists aaB <mecagonoisician@gmail.com> - 2013-04-17 12:25 +0200
  Re: a couple of things I don't understand wrt lists darnold <darnold992000@yahoo.com> - 2013-04-17 06:43 -0700

csiph-web