473,385 Members | 1,324 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Extended slice notation doesn't recognise integer

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

TypeError: sequence index must be integer
Jul 18 '05 #1
3 2349
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
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
Thanks. I'll upgrade python.
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Roberto A. F. De Almeida | last post by:
I found that when using negative indices, the slice object passed to __getitem__ depends on the number of slices. An example to clarify: class a: def __getitem__(self, index): return index ...
1
by: Steven Bethard | last post by:
Is there a reason that itertools.islice doesn't support None arguments for start and step? This would be handy for use with slice objects: >>> r = range(20) >>> s1 = slice(2, 10, 2) >>> s2 =...
4
by: Bob Hartung | last post by:
Hi all, I need to print the extended character set, the corners, vertical bars, crossing bars , etc in a console app. I can fudge it with #define topT char( 194 ) ; then, cout topT ;
9
by: J.Sperlhofer | last post by:
Good morning, Javascript-Professionals. I'm looking for an possibility to show a (calculated) 64bit-Number without exponential notation. I don't want to see exponational notation within my...
108
by: Bryan Olson | last post by:
The Python slice type has one method 'indices', and reportedly: This method takes a single integer argument /length/ and computes information about the extended slice that the slice object would...
40
by: Ron Adam | last post by:
After considering several alternatives and trying out a few ideas with a modified list object Bengt Richter posted, (Thank You), I think I've found a way to make slice operation (especially far end...
0
by: Josh Comley | last post by:
Hello! I have a problem, I can think of two methods for a solution, but cannot figure out how to implement them correctly! Aim: To disable and later enable an extended desktop setting (TV-OUT...
23
by: Antoon Pardon | last post by:
Now slices are objects in python, I was wondering if slice notation will be usable outside subscribtion in the future. Will it ever be possible to write things like: a = 4:9 for key, value in...
3
by: GavinCrooks | last post by:
The indices method of slice doesn't seem to work quite how I would expect when reversing a sequence. For example : '43210' '43210' So a slice with a negative step (and nothing else) reverses...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.