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


Groups > comp.lang.python > #77501

Re: Python is going to be hard

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ian.g.kelly@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'subject:Python': 0.06; '21,': 0.07; 'sys': 0.07; '34,': 0.09; '[1,': 0.09; 'indexes': 0.09; 'random': 0.14; '55,': 0.16; 'looping': 0.16; 'steve:': 0.16; 'index': 0.16; 'wrote:': 0.18; 'wed,': 0.18; 'print': 0.22; 'simpler': 0.24; 'math': 0.24; 'this:': 0.26; 'skip:" 20': 0.27; 'values': 0.27; 'header:In-Reply-To:1': 0.27; 'message- id:@mail.gmail.com': 0.30; '13,': 0.31; 'sep': 0.31; 'file': 0.32; '(most': 0.33; 'received:google.com': 0.35; 'really': 0.36; 'skip:> 10': 0.36; 'list': 0.37; 'list.': 0.37; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'most': 0.60; 'range': 0.61; 'first': 0.61; 'total': 0.65
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=ZQv29bSbM1AwDlE2JHcv3/bjloYAHgfkrE0AHh8T5Sc=; b=RmOEjS19kePd9MoryDPNtHaG28WRx4rW7fTlpmThYI0U9n9fRikNV2WI3herSgeIJJ n0kHbtkvKJgHylCEEtHx5+eOmcQMMFTesFl+/7ljsiSQzXT6vwS+AnM1WR8QpuUORvAr sOL62Q/7AE2lfoNM/clPx/5MQEdXSeWzY+4WLr1NkkuC5grLasXry1jxHePMonXfBCHQ z4BtIFKC+KuXTxccAvPRnWV39Ons849QQv7qe5omvVkwf1zMqmY/exYi5yIkQ82Z5fLi AwLf5gkuAIIa3ieRAZUIPApOFvJeOv9YoQLEVn4ksl1kZDBExoJNdUnBMe1vfBx0oaxG t9HA==
X-Received by 10.66.161.41 with SMTP id xp9mr34019242pab.120.1409771551300; Wed, 03 Sep 2014 12:12:31 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com>
References <d9me0ap5s0s28qaeobbh6680gciel6c1og@4ax.com> <9eoe0apt76pbd5slks20bjaq24m5mrqe3f@4ax.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Wed, 3 Sep 2014 13:11:51 -0600
Subject Re: Python is going to be hard
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
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 <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.13746.1409771560.18130.python-list@python.org> (permalink)
Lines 35
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1409771560 news.xs4all.nl 2851 [2001:888:2000:d::a6]:50261
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:77501

Show key headers only | View raw


On Wed, Sep 3, 2014 at 12:49 PM, Seymore4Head
<Seymore4Head@hotmail.invalid> wrote:
> On Wed, 03 Sep 2014 14:10:42 -0400, Seymore4Head
> <Seymore4Head@Hotmail.invalid> wrote:
>
>>import math
>>import random
>>import sys
>>b=[]
>>steve = [1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89]
>>for x in steve:
>>    print (steve[x])
>>
>>Traceback (most recent call last):
>>  File "C:\Functions\blank.py", line 7, in <module>
>>    print (steve[x])
>>IndexError: list index out of range
>
> Ok, I understand now that x is actually the first item in the list.
> What I want is a loop that goes from 1 to the total number of items in
> the list steve.

If you want the indexes also, you can do this:

for i, x in enumerate(steve):
    print(i, x)

If you really want just the indexes and not the values, then you can do this:

for i in range(len(steve)):
    print(i)

Most of the time though you will not need the indexes, and it will be
simpler just to work with the values by looping directly over the
list.

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


Thread

Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:10 -0400
  Re: Python is going to be hard John Gordon <gordon@panix.com> - 2014-09-03 18:17 +0000
    Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:52 -0400
      Re: Python is going to be hard mm0fmf <none@mailinator.com> - 2014-09-03 22:37 +0100
  Re: Python is going to be hard Rock Neurotiko <miguelglafuente@gmail.com> - 2014-09-03 20:16 +0200
  Re: Python is going to be hard Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-09-03 11:19 -0700
    Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:50 -0400
  Re: Python is going to be hard MRAB <python@mrabarnett.plus.com> - 2014-09-03 19:24 +0100
  Re: Python is going to be hard Skip Montanaro <skip@pobox.com> - 2014-09-03 13:28 -0500
    Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:52 -0400
  Re: Python is going to be hard Ethan Furman <ethan@stoneleaf.us> - 2014-09-03 11:33 -0700
    Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:41 -0400
      Re: Python is going to be hard Ethan Furman <ethan@stoneleaf.us> - 2014-09-03 12:49 -0700
  Re: Python is going to be hard Juan Christian <juan0christian@gmail.com> - 2014-09-03 15:44 -0300
    Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:56 -0400
  Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 14:49 -0400
    Re: Python is going to be hard Ethan Furman <ethan@stoneleaf.us> - 2014-09-03 11:55 -0700
      Re: Python is going to be hard Rob Gaddi <rgaddi@technologyhighland.invalid> - 2014-09-03 12:01 -0700
    Re: Python is going to be hard Ian Kelly <ian.g.kelly@gmail.com> - 2014-09-03 13:11 -0600
      Re: Python is going to be hard Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-03 15:22 -0400
    Re: Python is going to be hard Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-04 12:11 +1000
  Re: Python is going to be hard Denis McMahon <denismfmcmahon@gmail.com> - 2014-09-03 20:55 +0000
  Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 18:48 -0700
    Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 11:56 +1000
      Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 19:10 -0700
        Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 12:25 +1000
          Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 19:33 -0700
            Re: Python is going to be hard alister <alister.nospam.ware@ntlworld.com> - 2014-09-04 10:29 +0000
              Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-04 06:08 -0700
          Re: Python is going to be hard Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-04 23:25 +1000
            Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 23:55 +1000
      Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 20:22 -0700
        Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 13:49 +1000
          Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 21:11 -0700
            Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 15:02 +1000
              Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 23:23 -0700
                Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 16:39 +1000
                Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-04 06:15 -0700
                Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-04 23:30 +1000
                Re: Python is going to be hard Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-04 23:37 +1000
                Re: Python is going to be hard Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-04 15:04 +0100
                Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-05 00:08 +1000
                Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-04 19:24 -0700
                Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-05 12:30 +1000
                Re: Python is going to be hard Roy Smith <roy@panix.com> - 2014-09-04 22:51 -0400
                Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-04 19:56 -0700
                Re: Python is going to be hard Chris Angelico <rosuav@gmail.com> - 2014-09-05 13:08 +1000
        Re: Python is going to be hard Ethan Furman <ethan@stoneleaf.us> - 2014-09-03 21:06 -0700
          Re: Python is going to be hard Rustom Mody <rustompmody@gmail.com> - 2014-09-03 21:15 -0700

csiph-web