IndexError: pop index out of range

Discussion in 'Python' started by Andrew Z, May 15, 2013.

  1. Andrew Z

    Andrew Z Guest

    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>
    Andrew Z, May 15, 2013
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    36
    Views:
    1,574
    MonkeeSage
    Oct 11, 2006
  2. MRAB
    Replies:
    0
    Views:
    600
  3. Carlos Nepomuceno

    RE: IndexError: pop index out of range

    Carlos Nepomuceno, May 15, 2013, in forum: Python
    Replies:
    0
    Views:
    130
    Carlos Nepomuceno
    May 15, 2013
  4. Titiksha Joshi

    indexerror: list index out of range??

    Titiksha Joshi, Jun 29, 2013, in forum: Python
    Replies:
    8
    Views:
    128
    Steven D'Aprano
    Jul 1, 2013
  5. Replies:
    4
    Views:
    63
    Peter Otten
    May 16, 2014
Loading...

Share This Page