Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin2!goblin.stu.neva.ru!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.016 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'pop': 0.05; 'main()': 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; 'examples': 0.20; 'print': 0.22; 'words': 0.29; 'errors': 0.30; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; '"': 0.31; 'file': 0.32; '(most': 0.33; 'basic': 0.35; "can't": 0.35; 'received:google.com': 0.35; 'skip:& 10': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; '\xa0\xa0\xa0': 0.39; 'to:addr:python.org': 0.39; 'range': 0.61; '8bit%:100': 0.72; '\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0\xa0': 0.84; 'skip:& 80': 0.91 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=Hm1kS/pNEH7U2oULkpKaQWk3n8h2YR+9RWg/fdoSRhw=; b=iJD/gsXVT4CJnukYBhkFR/fqHj23p+JOyYCDa9etTUSm8tQT+DeTgarxF0J8qNWbIg 5duqax1ctgB180Gp9EuHgtcTpFDRkcJZwNG/0KB12qwHdovoAz7jQBgLwX2ZyqRHI4Be vad5nMlTmrelmHzQggx16E1PFym95Vsx0MuASVlbtNffqPYoKAUzPil2PsmN/wmD2Ylc hfhwnjVgd2TC0XJSkUrtFaTR2QeYGtzQT7KWMFr6/rzhJY+R+44ZQql+cHm8pK/gv2J3 WFZqhaWxwXjAPlN5hQBZA6Vhb4pn2pj/aTGmFoOh+DtF4tuA0f/eI827BRUFVs9+NHS5 hebg== X-Received: by 10.152.170.199 with SMTP id ao7mr16837694lac.51.1368591766013; Tue, 14 May 2013 21:22:46 -0700 (PDT) MIME-Version: 1.0 From: Andrew Z Date: Wed, 15 May 2013 00:22:05 -0400 Subject: IndexError: pop index out of range To: python-list@python.org Content-Type: multipart/alternative; boundary=089e01176b290e4cd104dcba1a30 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: 106 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1368591775 news.xs4all.nl 15914 [2001:888:2000:d::a6]:40172 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:45322 --089e01176b290e4cd104dcba1a30 Content-Type: text/plain; charset=ISO-8859-1 hello, going fru some basic examples and can't figureout why the following errors out. Help is very much appreciated: 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 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 --089e01176b290e4cd104dcba1a30 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
hello,
=A0going fru some basic examples= and can't figureout why the following errors out. Help is very much ap= preciated:
<code>
def front_x(words):
=A0 # +++your co= de here+++
=A0=A0=A0 print "words passed : ", words
=A0=A0=A0 list_xx =3D= []
=A0=A0=A0 list_temp =3D words[:]
=A0=A0=A0 print "list_temp = -", list_temp
=A0=A0=A0 print "words -", words
=A0=A0= =A0 for idx, val in enumerate(words):
=A0=A0=A0=A0=A0=A0=A0 print val, idx
=A0=A0=A0=A0=A0=A0=A0 # str_idx =3D= val.find('x',0,2)
=A0=A0=A0=A0=A0=A0=A0 if val[0] =3D=3D 'x= ':
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 vl =3D list_temp.pop(idx)
= =A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 list_xx.append(vl)
=A0=A0=A0=A0=A0=A0= =A0=A0=A0=A0=A0=A0=A0=A0=A0
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 print &qu= ot;appending list_xx", list_xx

=A0=A0=A0 list_xx.sort
=A0=A0=A0 list_temp.sort
=A0=A0=A0 print &= quot;words sorted : " + str(words)
=A0=A0=A0 print "list_temp = sorted : ", list_temp
=A0=A0=A0 list_xx.append(words)
=A0=A0=A0 = print "list_xx" + str(list_xx)
=A0=A0=A0 return True

front_x
words passed : ['bbb',= 'ccc', 'axx', 'xzz', 'xaa']
list_temp -= ['bbb', 'ccc', 'axx', 'xzz', 'xaa'= ]
words - ['bbb', 'ccc', 'axx', 'xzz', 'x= aa']
bbb 0
ccc 1
axx 2
xzz 3
appending list_xx ['xzz= ']
xaa 4
Traceback (most recent call last):
=A0 File "/ho= me/az/work/Python/Google_Course/google-python-exercises/basic/list1.py"= ;, line 119, in <module>
=A0=A0=A0 main()
=A0 File "/home/az/work/Python/Google_Course/googl= e-python-exercises/basic/list1.py", line 100, in main
=A0=A0=A0 tes= t(front_x(['bbb', 'ccc', 'axx', 'xzz', '= ;xaa']),
=A0 File "/home/az/work/Python/Google_Course/google-python-exercises/b= asic/list1.py", line 55, in front_x
=A0=A0=A0 vl =3D list_temp.pop(= idx)
IndexError: pop index out of range

</code>
--089e01176b290e4cd104dcba1a30--