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


Groups > comp.lang.python > #45323

RE: IndexError: pop index out of range

Path csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <carlosnepomuceno@outlook.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.021
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'pop': 0.05; 'main()': 0.09; 'parsing': 0.09; 'val': 0.09; 'def': 0.12; '55,': 0.16; 'idx': 0.16; 'idx,': 0.16; 'indexerror:': 0.16; 'skip:" 70': 0.16; 'val,': 0.16; 'index': 0.16; 'wed,': 0.18; 'examples': 0.20; 'to:name:python-list@python.org': 0.22; 'print': 0.22; 'header:In- Reply-To:1': 0.27; 'to:2**1': 0.27; 'words': 0.29; 'errors': 0.30; 'url:mailman': 0.30; 'code': 0.31; 'file': 0.32; 'url:python': 0.33; 'running': 0.33; '(most': 0.33; 'date:': 0.34; 'basic': 0.35; "can't": 0.35; 'url:listinfo': 0.36; 'url:org': 0.36; 'email addr:python.org': 0.37; 'to:addr:python-list': 0.38; 'recent': 0.39; 'skip:_ 30': 0.39; 'subject:': 0.39; 'to:addr:python.org': 0.39; 'url:mail': 0.40; 'remove': 0.60; 'range': 0.61; 'email addr:gmail.com': 0.63; 'received:65.55.111': 0.63; 'email name :python-list': 0.65; 'to:addr:gmail.com': 0.65; 'received:65.55.111.72': 0.84; '2013': 0.98
X-TMN [6V3u4cf8s0qeCBl6qE/sIgbWJwvR4n//]
X-Originating-Email [carlosnepomuceno@outlook.com]
From Carlos Nepomuceno <carlosnepomuceno@outlook.com>
To Andrew Z <formisc@gmail.com>, "python-list@python.org" <python-list@python.org>
Subject RE: IndexError: pop index out of range
Date Wed, 15 May 2013 07:53:26 +0300
Importance Normal
In-Reply-To <CAPrcKXKuu_rr7veF_qLHz-bcLaBBZf_+RR+mY+zXwxGCO1H0BA@mail.gmail.com>
References <CAPrcKXKuu_rr7veF_qLHz-bcLaBBZf_+RR+mY+zXwxGCO1H0BA@mail.gmail.com>
Content-Type text/plain; charset="iso-8859-1"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-OriginalArrivalTime 15 May 2013 04:53:26.0836 (UTC) FILETIME=[23047740:01CE5128]
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.1687.1368593674.3114.python-list@python.org> (permalink)
Lines 70
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1368593674 news.xs4all.nl 15981 [2001:888:2000:d::a6]:44918
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:45323

Show key headers only | View raw


Your "for idx, val in enumerate(words):" is running on words not list_temp.
As you remove from list_temp and keeps parsing words you get the IndexError.
________________________________
> From: formisc@gmail.com 
> Date: Wed, 15 May 2013 00:22:05 -0400 
> Subject: IndexError: pop index out of range 
> To: python-list@python.org 
>  
> hello, 
>   going fru some basic examples and can't figureout why the following  
> errors out. Help is very much appreciated: 
> <code> 
> def front_x(words): 
>    # +++your code here+++ 
>      print "words passed : ", words 
>      list_xx = [] 
>      list_temp = words[:] 
>      print "list_temp -", list_temp 
>      print "words -", words 
>      for idx, val in enumerate(words): 
>          print val, idx 
>          # str_idx = val.find('x',0,2) 
>          if val[0] == 'x': 
>              vl = list_temp.pop(idx) 
>              list_xx.append(vl) 
>  
>              print "appending list_xx", list_xx 
>  
>      list_xx.sort 
>      list_temp.sort 
>      print "words sorted : " + str(words) 
>      print "list_temp sorted : ", list_temp 
>      list_xx.append(words) 
>      print "list_xx" + str(list_xx) 
>      return True 
>  
> front_x 
> words passed : ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> list_temp - ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> words - ['bbb', 'ccc', 'axx', 'xzz', 'xaa'] 
> bbb 0 
> ccc 1 
> axx 2 
> xzz 3 
> appending list_xx ['xzz'] 
> xaa 4 
> Traceback (most recent call last): 
>    File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 119, in <module> 
>      main() 
>    File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 100, in main 
>      test(front_x(['bbb', 'ccc', 'axx', 'xzz', 'xaa']), 
>    File  
> "/home/az/work/Python/Google_Course/google-python-exercises/basic/list1.py",  
> line 55, in front_x 
>      vl = list_temp.pop(idx) 
> IndexError: pop index out of range 
>  
> </code> 
>  
> -- http://mail.python.org/mailman/listinfo/python-list 		 	   		  

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


Thread

RE: IndexError: pop index out of range Carlos Nepomuceno <carlosnepomuceno@outlook.com> - 2013-05-15 07:53 +0300

csiph-web