Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #43682
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!news.glorb.com!news-out.readnews.com!transit4.readnews.com!panix!gordon |
|---|---|
| From | John Gordon <gordon@panix.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: a couple of things I don't understand wrt lists |
| Date | Tue, 16 Apr 2013 16:43:23 +0000 (UTC) |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Lines | 53 |
| Message-ID | <kkjv3b$9pj$1@reader1.panix.com> (permalink) |
| References | <mailman.668.1366126626.3114.python-list@python.org> |
| NNTP-Posting-Host | panix2.panix.com |
| X-Trace | reader1.panix.com 1366130603 10035 166.84.1.2 (16 Apr 2013 16:43:23 GMT) |
| X-Complaints-To | abuse@panix.com |
| NNTP-Posting-Date | Tue, 16 Apr 2013 16:43:23 +0000 (UTC) |
| User-Agent | nn/6.7.3 |
| Xref | csiph.com comp.lang.python:43682 |
Show key headers only | View raw
In <mailman.668.1366126626.3114.python-list@python.org> aaB <mecagonoisician@gmail.com> writes:
> but when I do:
> for i in rule:
> print rule[i]
> I get the "complement":
> 1
> 1
> 1
> 1
> 0
> 1
> 1
> 1
When you iterate over a list with this statement:
for i in rule:
i contains each successive list item.
However, your code:
print rule[i]
acts as though i is the list item's *subscript*, which is incorrect.
In effect, your code is doing this:
print rule[0]
print rule[0]
print rule[0]
print rule[0]
print rule[1]
print rule[0]
print rule[0]
print rule[0]
Although in your example both rule[0] and rule[1] are zero, so I
don't know why '1' ever got printed.
Also, as far as I can tell, this code should not have worked at all:
for i in range(rule):
print rule[i]
The range() function expects an integer, not a list.
--
John Gordon A is for Amy, who fell down the stairs
gordon@panix.com B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
a couple of things I don't understand wrt lists aaB <mecagonoisician@gmail.com> - 2013-04-16 17:37 +0200
Re: a couple of things I don't understand wrt lists John Gordon <gordon@panix.com> - 2013-04-16 16:43 +0000
Re: a couple of things I don't understand wrt lists Larry Hudson <orgnut@yahoo.com> - 2013-04-16 21:57 -0700
Re: a couple of things I don't understand wrt lists Serhiy Storchaka <storchaka@gmail.com> - 2013-04-17 12:35 +0300
Re: a couple of things I don't understand wrt lists 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-17 09:10 -0700
Re: a couple of things I don't understand wrt lists Ned Batchelder <ned@nedbatchelder.com> - 2013-04-17 14:36 -0400
Re: a couple of things I don't understand wrt lists Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-18 04:46 +1000
Re: a couple of things I don't understand wrt lists Chris Angelico <rosuav@gmail.com> - 2013-04-18 04:42 +1000
Re: a couple of things I don't understand wrt lists 88888 Dihedral <dihedral88888@googlemail.com> - 2013-04-17 09:10 -0700
csiph-web