Path: csiph.com!usenet.pasdenom.info!news.etla.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.034 X-Spam-Evidence: '*H*': 0.93; '*S*': 0.00; 'beginner': 0.05; 'output': 0.05; '[0,': 0.09; 'pointers': 0.09; 'python': 0.11; 'def': 0.12; 'project,': 0.12; 'wrote': 0.14; '2.7': 0.14; 'integers,': 0.16; 'png': 0.16; 'script,': 0.16; 'scripts.': 0.16; 'thanks,': 0.17; 'bit': 0.19; 'trying': 0.19; 'programming': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'script': 0.25; 'asking': 0.27; 'tried': 0.27; 'function': 0.29; 'appreciated.': 0.29; 'list:': 0.30; 'code': 0.31; 'post.': 0.31; 'preliminary': 0.31; 'linux': 0.33; 'running': 0.33; "i'd": 0.34; "can't": 0.35; 'something': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'really': 0.36; 'doing': 0.36; "didn't": 0.36; 'charset:us-ascii': 0.36; 'half': 0.37; 'list': 0.37; 'represent': 0.38; 'message-id:@gmail.com': 0.38; 'whatever': 0.38; 'to:addr:python-list': 0.38; 'issue': 0.38; 'list,': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'system.': 0.39; 'is.': 0.60; 'ago,': 0.61; 'length': 0.61; 'further': 0.61; 'content-disposition:inline': 0.62; 'more': 0.64; 'here': 0.66; 'statement,': 0.68; 'results': 0.69; 'cellular': 0.84; 'console,': 0.84; 'good:': 0.84; 'do:': 0.91; 'same,': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:date:from:to:subject:message-id:mail-followup-to :mime-version:content-type:content-disposition:user-agent; bh=D83vKrI9JDJj2kIEksqQzoG+MnxlOGNVOC0T6t1EOik=; b=nGNiPl+ZLftEWBthYPZasnPm9jsS58tWwtZKQVWLBL7QHvpXfxGoZnsXBBfIUA0MfM PaVcyciwd+SmBDc4MKsCRli2Sql6c9ym7ByPGT57SoUlUfOI7O9iEhjWL82y77wTAEC8 us/Tq6IqDjmyYduunruXSRI48yGCSd9ayZ52i2qmR0W+FbnxjNYj3NJ7xjHVRGromuyA 5aI/7rOTOFiA/UeMbppVF5BlF2mQmmVe45xCOIOAkCK2hYsHu1dv+hthIlxbAw8CeoQC pRmjnzAPXm1spwnEQCAp9lZgNgZaiX0Vb3kTBQaLN0CW6FL9BikaCjBlBfIgVvVzMFEQ 0Pfw== X-Received: by 10.180.79.6 with SMTP id f6mr19890103wix.26.1366126624142; Tue, 16 Apr 2013 08:37:04 -0700 (PDT) Date: Tue, 16 Apr 2013 17:37:01 +0200 From: aaB To: py-list Subject: a couple of things I don't understand wrt lists Mail-Followup-To: py-list MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 79 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1366126626 news.xs4all.nl 2654 [2001:888:2000:d::a6]:52513 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:43675 hello, I am a beginner programmer. I started learning programming about a year and a half ago, using C. I picked up python a few months ago, but only wrote very few scripts. I am currently trying to learn more about the python way of doing things by writing a script that generates png images using a 1D cellular automaton. While writing preliminary code for that project, I ran into a behaviour that I don't understand. I am using python 2.7 on a linux system. I represent the CA's rule with a list of integers, of value 1 or 0. Here is the function I use to generate the list: def get_rule(rulenum): rule = [] while rulenum > 0: rule.append(rulenume % 2) rulenum /= 2 while len(rule) < 8: rule.append(0) rule.reverse() return rule if i call it by writing: rule = getrule(int(8)) and then call: print rule the output is good: [0, 0, 0, 0, 1, 0, 0, 0] I then tried to print each item of the list using a for loop: for i in range(rule): print rule[i] the output is, as expected: 0 0 0 0 1 0 0 0 but when I do: for i in rule: print rule[i] I get the "complement": 1 1 1 1 0 1 1 1 There must be something I didn't understand correctly in the for statement, but I really can't think of a reason why the output is what it is. I tried this using the interactive console, and the results are the same, whatever the length of the list, i always get the complement of my bit pattern. Any pointers to help me understand this would be appreciated. I am also running into an other issue with this script, but I'd rather understand this before asking further questions. Thanks, and sorry for the rather long post.