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