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


Groups > comp.lang.python > #43677

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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!xlned.com!feeder1.xlned.com!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <rosuav@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.140
X-Spam-Level *
X-Spam-Evidence '*H*': 0.77; '*S*': 0.05; 'iterate': 0.09; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'underlying': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'print': 0.22; 'sort': 0.25; 'this:': 0.26; 'values': 0.27; 'header:In-Reply- To:1': 0.27; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'problem': 0.35; 'subject:lists': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'sometimes': 0.38; 'to:addr :python-list': 0.38; 'rather': 0.38; 'to:addr:python.org': 0.39; 'obvious': 0.74; 'confusion.': 0.84; 'careful': 0.91; 'do:': 0.91; '2013': 0.98
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:x-received:in-reply-to:references:date:message-id :subject:from:to:content-type; bh=ZA5YHh99HuBCuLIkuQids3MkW2ZDwpHrTimRBKk5wns=; b=kzg7OLi8Qn5hhU+r3oL7s561AHrHlWaOiJdR8D2HkJnVGxjRFQJWLfz7hlsMSPZaOh 5x3HvzWHh5AwzfI90Z1XAsXiJr4/LgfOKTeWURd7vPMXBtdoqyn45m+Gm4KixknucYjo wEoEeA2et4e/zXPwlt53iYBX78wLrhX79PhWzwwrFcbKcDlieILqzBONwT6uH/2BOocb ojW8Th4xWtCSSCMpYy2Ds87k55LwK42DYyP3yNMnHYC0KMgpHN2WwAEy+Sncd82tydNX ukziY7s7opIkKZX2WBIQCFuGrw0P2gNJ2aJkCEjOJnMJZEXng4pN5HsG/JytHByTwr7F ntsA==
MIME-Version 1.0
X-Received by 10.52.231.231 with SMTP id tj7mr1633363vdc.111.1366126986464; Tue, 16 Apr 2013 08:43:06 -0700 (PDT)
In-Reply-To <20130416153701.GA18377@gmail.com>
References <20130416153701.GA18377@gmail.com>
Date Wed, 17 Apr 2013 01:43:06 +1000
Subject Re: a couple of things I don't understand wrt lists
From Chris Angelico <rosuav@gmail.com>
To python-list@python.org
Content-Type text/plain; charset=ISO-8859-1
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.669.1366126994.3114.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1366126994 news.xs4all.nl 2701 [2001:888:2000:d::a6]:56305
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:43677

Show key headers only | View raw


On Wed, Apr 17, 2013 at 1:37 AM, aaB <mecagonoisician@gmail.com> wrote:
> but when I do:
>
> for i in rule:
>   print rule[i]

When you iterate over rule, you don't iterate over the indices, but
over the values themselves. Try this:

for i in rule:
    print i

Incidentally, "for i in range(rule)" isn't actually going to work;
what you would have used is "for i in range(len(rule))". Be careful
with that sort of thing; it's usually safest to actually copy and
paste from an interactive session, rather than reconstruct manually.
Sometimes it's not obvious whether it was a copy/paste problem or the
cause of your underlying confusion.

ChrisA

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


Thread

Re: a couple of things I don't understand wrt lists Chris Angelico <rosuav@gmail.com> - 2013-04-17 01:43 +1000

csiph-web