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))
[2, 4, 6, 8] list(itertools.islice(r, s2.start, s2.stop, s2.step))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: an integer is required list(itertools.islice(r, s2.start, s2.stop, s2.step or 1))
[2, 3, 4, 5, 6, 7, 8, 9] list(itertools.islice(r, s3.start, s3.stop, s3.step))
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: an integer is required list(itertools.islice(r, s3.start or 0, s3.stop, s3.step or 1))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Of course, I can get (start, stop, step) tuples with slice.indices, but
only if I know the length of the iterable, which kinda defeats the
purpose of using itertools...
list(itertools.islice(r, *s2.indices(10)))
[2, 3, 4, 5, 6, 7, 8, 9] list(itertools.islice(r, *s3.indices(10)))
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Steve 1 3767
[Steven Bethard] 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
Offhand, this seems like a reasonable idea. Please file a Py2.5 feature request
and assign to me.
Of course, I can get (start, stop, step) tuples with slice.indices, but only if I know the length of the iterable, which kinda defeats the purpose of using itertools...
The main purpose is to extract elements one at time instead of all at once.
This memory friendly approach results in better scalability.
Raymond Hettinger This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Dan Williams |
last post by:
Is there any interest in adding a "Haskellish" take function to
itertools? I know its easy enough to roll my own, I've been using:
take = lambda iter, n:
which works, but I was wondering if...
|
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
...
|
by: Steven Bethard |
last post by:
Jack Diederich wrote:
>
> itertools to iter transition, huh? I slipped that one in, I mentioned
> it to Raymond at PyCon and he didn't flinch. It would be nice not to
> have to sprinkle 'import...
|
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...
|
by: Alexandre Guimond |
last post by:
Hi all,
i'm trying to deepcopy a slice object but i get the following error.
Does anyone know a workaround?
ActivePython 2.4.3 Build 12 (ActiveState Software Inc.) based on
Python 2.4.3 (#69,...
| |
by: Mathias Panzenboeck |
last post by:
I wrote a few functions which IMHO are missing in python(s itertools).
You can download them here:
http://sourceforge.net/project/showfiles.php?group_id=165721&package_id=212104
A short...
|
by: =?gb2312?B?yMvR1MLkyNXKx8zs0cSjrM37vKvM7NHEsru8+7z |
last post by:
I'm a python newbie. It seems the slice operation will do copy.
for example:
if the list have large members, the slice operations will consume many
times.
for instance, I have a long...
|
by: Matthew Wilson |
last post by:
I want to write a function that each time it gets called, it returns a
random choice of 1 to 5 words from a list of words.
I can write this easily using for loops and random.choice(wordlist) and...
|
by: bearophileHUGS |
last post by:
I find itertools.islice() useful, so for Python 3.x I may like to see
it removed from the itertools module, and the normal slicing syntax
extended to work with generators/iterators too.
from...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
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,...
|
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...
|
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...
|
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...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |