Why does the following code give this error: [0, 1, 2, 3, 4][::2]
TypeError: sequence index must be integer 3 2360
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.
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
Thanks. I'll upgrade python. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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
>>> b = a()
>>> print b
Traceback (most recent call last):
|
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 = slice(2, 10)
>>> s3 = slice(10)
>>> list(itertools.islice(r, s1.start, s1.stop, s1.step))
>>> list(itertools.islice(r, s2.start, s2.stop, s2.step))
|
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 ;
|
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 binary numbers.
To demonstrate my problem, try this code:
----
var binNumber = Math.pow(2,61);
|
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 describe if applied to a sequence of length
items. It returns a tuple of three integers; respectively
these are the /start/ and /stop/ indices and the /step/ or
stride length of the slice. Missing or out-of-bounds indices
are handled in a manner...
| |
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 indexing)
symmetrical and more consistent.
So to find out if this is indeed a possibility, it would be nice to get
a few opinions at this point. So blast away... or hopefully tell me
what you like about it instead. ;-)
(Any suggestions or...
|
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 of a
graphics card).
Idea 1:
|
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 tree.items('alfa.': 'beta.'):
--
Antoon Pardon
|
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 the
sequence. But what are the
corresponding indices?
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |