IndexError: pop index out of range

Andrew Z formisc at gmail.com
Wed May 15 00:22:05 EDT 2013


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>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20130515/41308ca9/attachment.html>


More information about the Python-list mailing list