473,395 Members | 1,484 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,395 software developers and data experts.

what's the only one obvious way?

This came up in the Italian newsgroup; I take the occasion to bring
the question here since it is something which puzzled me for a while.
The question is when we are expected to use itertools and when we
are expected to use generator expressions. Consider these examples:

# from itertools recipes in the 2.4a1 docs
def all(seq, pred=bool):
"Returns True if pred(x) is True for every element in the iterable"
return False not in imap(pred, seq)

def any(seq, pred=bool):
"Returns True if pred(x) is True at least one element in the iterable"
return True in imap(pred, seq)

# alternative versions
def all(seq, pred=bool):
return False not in (pred(x) for x in seq)

def any(seq, pred=bool):
return True in (pred(x) for x in seq)

I maintain that it is *not obvious* to prefer one choice over the other
and this is BAD. So where are the style-guides? Is the itertools module
going to be deprecated even before it is finished ??

The point is that the mindset to use itertools is pretty different
from the mindset to use generator expressions, in the same sense
of the difference between map, filter and list comprehensions.

It seems to me that list comprehensions won; also Guido publicly said
and repeated that he never liked the contributed functional stuff (filter,
map, reduce, lambda) so there is a guidance here (even if I will continue
to use them no matter what Guido says ;)

But if a younger pythonista ask me what should he use between
itertools and generator comprehensions I don't know what to say
(of course I suggest him the more readable solution but in the
example before it is purely subjective to decide which is the more
readable solution).
Can somebody channel Guido thoughts on this issue, please?

Thanks,
Michele Simionato
Jul 18 '05 #1
1 1242
mi***************@gmail.com (Michele Simionato) writes:
Can somebody channel Guido thoughts on this issue, please?


Use generator expressions. The whole existence of an add-on itertools
module pointed to something being missing from the base language.
That something was generator expressions.
Jul 18 '05 #2

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

Similar topics

226
by: Stephen C. Waterbury | last post by:
This seems like it ought to work, according to the description of reduce(), but it doesn't. Is this a bug, or am I missing something? Python 2.3.2 (#1, Oct 20 2003, 01:04:35) on linux2 Type...
33
by: Diez B. Roggisch | last post by:
Hi, today I rummaged through the language spec to see whats in the for ... else: for me. I was sort of disappointed to learn that the else clauses simply gets executed after the loop-body -...
92
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption?...
137
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very...
125
by: Sarah Tanembaum | last post by:
Beside its an opensource and supported by community, what's the fundamental differences between PostgreSQL and those high-price commercial database (and some are bloated such as Oracle) from...
18
by: Jm | last post by:
Hi all I feel stupid for asking this, but i just went to use the left() function from vb6 only to find it doesnt do what it used to under .NET. Im assuming theres something else now im meant to...
44
by: Tolga | last post by:
As far as I know, Perl is known as "there are many ways to do something" and Python is known as "there is only one way". Could you please explain this? How is this possible and is it *really* a...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
14
by: raylopez99 | last post by:
Question: the "myList" below is the same (works the same) whether instantiated inside the (normal) constructor, as below, and as my standard practice, or outside? RL public class AClass {...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
jinu1996
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...
0
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...
0
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...

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.