473,721 Members | 2,259 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

iter(callable, sentinel)

Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?
Thanks,

Will McGugan

--
work: http://www.kelpiesoft.com
blog: http://www.willmcgugan.com
Jul 27 '06 #1
3 2862

Will McGugan wrote:
Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?
Thanks,

Will McGugan

--
work: http://www.kelpiesoft.com
blog: http://www.willmcgugan.com
I just found out about that recently too.

help(iter) shows this:
Help on built-in function iter in module __builtin__:

iter(...)
iter(collection ) -iterator
iter(callable, sentinel) -iterator

Get an iterator from an object. In the first form, the argument
must
supply its own iterator, or be a sequence.
In the second form, the callable is called until it returns the
sentinel.

Jul 27 '06 #2
Will McGugan wrote:
Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?
Thanks,

Will McGugan

--
work: http://www.kelpiesoft.com
blog: http://www.willmcgugan.com
D'oh! You said *elaborate*... Sorry. Fredrik Lundh gives a great
example of it's use in this thread:
http://groups.google.ca/group/comp.l...f71597917afaa3

Peace,
~Simon

Jul 27 '06 #3
Will McGugan wrote:
Hi,

I've been using Python for years, but I recently encountered something
in the docs I wasnt familar with. That is, using two arguements for
iter(). Could someone elaborate on the docs and maybe show a typical use
case for it?
Thanks,

Will McGugan

--
work: http://www.kelpiesoft.com
blog: http://www.willmcgugan.com
Also, FWIW, GvR said this (parentheticall y) about a week ago on the
Python-3000 list: "I also think that the two-argument form
iter(function, sentinel) is not very successful or useful and might be
dropped, but that's a separate issue."

Jul 27 '06 #4

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

Similar topics

9
2687
by: Francis Avila | last post by:
A little annoyed one day that I couldn't use the statefulness of generators as "resumable functions", I came across Hettinger's PEP 288 (http://www.python.org/peps/pep-0288.html, still listed as open, even though it's at least a year old and Guido doesn't seem very hot on the idea). I'm not too sure of its ideas on raising exceptions in generators from outside (although it looks like it might be convenient in some cases), but being able...
21
2179
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 itertools as it' in code. iter could also > become a type wrapper instead of a function, so an iter instance could > be a wrapper that figures out whether to call .next or __getitem__ > depending on it's argument. > for item in...
1
1303
by: Steven Bethard | last post by:
Michael Spencer wrote: > While we're on the topic, what do you think of having unary, > non-summary builtins automatically map themselves when called with an > iterable that would otherwise be an illegal argument: > > e.g., > int(iterable) -> (int(i) for i in iterable) > ord(iterable) -> (ord(i) for i in iterable) > >
21
1828
by: Daniel Schüle | last post by:
Hello NG, I am wondering if there were proposals or previous disscussions in this NG considering using 'while' in comprehension lists # pseudo code i=2 lst= of course this could be easily rewritten into
9
3503
by: none | last post by:
Hi all, First, let me preface this by the fact that I'm completely new to the language, but not to programming in general. I'm trying to get my feet wet with something near and dear to my heart: database programming. Here's what I've got: import pgdb;
9
1813
by: Neil Cerutti | last post by:
def is_iterable(obj): try: iter(obj) return True except TypeError: return False Is there a better way? --
3
2831
by: gert | last post by:
what is the difference between iter(lambda:f.read(8192), ') and iter(f.read(8192),'') ?
11
1402
by: Erich | last post by:
Hello all, Today I found myself once again defining two functions that I use all the time: nsplit and iterable. These little helper functions of mine get used all the time when I work. Im sick of having to define them (but am very good at it these days, less than 1 typo per function!). It leads me to the following questions 1. Is this functionality already built in and im just missing it 2. Is there some well known, good technique...
1
1130
by: mh | last post by:
What's the best Python idiom for this C construct? while ((x = next()) != END) { .... } Now I'm doing x = next() while x != END:
0
8858
marktang
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8738
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9376
Oralloy
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...
0
9085
tracyyun
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...
0
8026
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5994
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();...
1
3207
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 we have to send another system
2
2596
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2146
bsmnconsultancy
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.