Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #45322 > unrolled thread
| Started by | Andrew Z <formisc@gmail.com> |
|---|---|
| First post | 2013-05-15 00:22 -0400 |
| Last post | 2013-05-15 00:22 -0400 |
| Articles | 1 — 1 participant |
Back to article view | Back to comp.lang.python
IndexError: pop index out of range Andrew Z <formisc@gmail.com> - 2013-05-15 00:22 -0400
| From | Andrew Z <formisc@gmail.com> |
|---|---|
| Date | 2013-05-15 00:22 -0400 |
| Subject | IndexError: pop index out of range |
| Message-ID | <mailman.1686.1368591775.3114.python-list@python.org> |
[Multipart message — attachments visible in raw view] — view raw
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>
Back to top | Article view | comp.lang.python
csiph-web