By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,814 Members | 1,136 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,814 IT Pros & Developers. It's quick & easy.

Extended slice notation doesn't recognise integer

P: n/a
Why does the following code give this error:
[0, 1, 2, 3, 4][::2]

TypeError: sequence index must be integer
Jul 18 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Thomas Covello wrote:
Why does the following code give this error:
[0, 1, 2, 3, 4][::2]
TypeError: sequence index must be integer


This is what I get:
[0, 1, 2, 3, 4][::2]

[0, 2, 4]

Are you using 2.3.x? I believe extended slices didn't show up until 2.3.
Jul 18 '05 #2

P: n/a
Thomas Covello wrote:
Why does the following code give this error:
[0, 1, 2, 3, 4][::2]
TypeError: sequence index must be integer


In Python 2.2 lists did not support extended slice notation but in 2.3
they do.

Python 2.3.2 (#4, Feb 2 2004, 00:30:40)
[GCC 3.1 20020420 (prerelease)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
[0, 1, 2, 3, 4][::2]

[0, 2, 4]

http://www.python.org/peps/pep-0283.html
"This document describes the development and release schedule for Python
2.3."

"Extended slice notation for all built-in sequences. The patch by
Michael Hudson is now all checked in."

Paul Prescod

Jul 18 '05 #3

P: n/a
Thanks. I'll upgrade python.
Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.