The Artima Developer Community
Sponsored Link

Python Buzz Forum
You wait all day for a bus…

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Thomas Guest

Posts: 236
Nickname: tag
Registered: Nov, 2004

Thomas Guest likes dynamic languages.
You wait all day for a bus… Posted: Oct 2, 2013 2:54 PM
Reply to this message Reply

This post originated from an RSS feed registered with Python Buzz by Thomas Guest.
Original Post: You wait all day for a bus…
Feed Title: Word Aligned: Category Python
Feed URL: http://feeds.feedburner.com/WordAlignedCategoryPython
Feed Description: Dynamic languages in general. Python in particular. The adventures of a space sensitive programmer.
Latest Python Buzz Posts
Latest Python Buzz Posts by Thomas Guest
Latest Posts From Word Aligned: Category Python

Advertisement

Any and all didn’t appear in Python until version 2.5, released in 2006, when the language was already well into its teens.

Why the delay in offering such fundamental functions? An oversight? Or simply that they’re so easy to implement they weren’t thought necessary. Either way, they’re here now.

The functions are closely related and complementary. We can define any in terms of all and vice-versa.

def any_(xs):
    return not all(map(operator.not_, xs))

def all_(xs):
    return not any(map(operator.not_, xs))

C++ reached its 30s before introducing its own versions of these logical algorithms, any_of and all_of, but made up for lost time by finding room for a third, none_of, which is not any_of.

template <class Iter, class Pred>
bool none_of_(Iter b, Iter e, Pred p)
{
    return std::find_if(b, e, p) == e;
}

template <class Iter, class Pred>
bool any_of_(Iter b, Iter e, Pred p)
{
    return !none_of_(b, e, p);
}

template <class Iter, class Pred>
bool all_of_(Iter b, Iter e, Pred p)
{
    return !any_of_(b, e, std::not1(p));
}

Read: You wait all day for a bus…

Topic: Campbell Walsh Urology 11th Edition will revise PVPS risks to 1-2% of patients Previous Topic   Next Topic Topic: An introduction to Sealing Coffee

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use