Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8520819
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T06:38:17+00:00 2026-06-11T06:38:17+00:00

Given the example below, which is more pythonic? Using function composition, lambdas, or (now

  • 0

Given the example below, which is more pythonic? Using function composition, lambdas, or (now for) something completely different? I have to say that the lambdas seem to be more readable, but Guido himself seems to want to remove lambdas altogether – http://www.artima.com/weblogs/viewpost.jsp?thread=98196

from functools import partial
from operator import not_, ge

def get_sql_data_type_from_string(s):
    s = str(s)

    # compose(*fs) -> returns composition of functions fs
    # iserror(f, x) -> returns True if Exception thrown from f(x), False otherwise

    # Using function composition
    predicates = (
        ('int',     compose(not_, partial(iserror, int))),
        ('float',   compose(not_, partial(iserror, float))),
        ('char',    compose(partial(ge, 1), len)))

    # Using lambdas
    predicates = (
        ('int',     lambda x: not iserror(int, x)),
        ('float',   lambda x: not iserror(float, x)),
        ('char',    lambda x: len(x) <= 1))

    # Test each predicate
    for i, (t, p) in enumerate(predicates):
        if p(s):
            return i, t

    # If all predicates fail
    return (i + 1), 'varchar'
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T06:38:18+00:00Added an answer on June 11, 2026 at 6:38 am

    A programmer who has never seen Python will be able to figure out the lambda at a glance. I’ve been using Python for over ten years, and I was scratching my head to figure out the composition form, even with the lambda version to compare against.

    Go for the one that doesn’t suck. Also, given that lambda made the 3.0 cut, I doubt it will ever be removed.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string.An example is given below. [playlist]\r\npath1=url1\r\npath2=url2\r\npath=url3\r\npath4=url4\r\ncount=1 How can I extract path
I have an array of as given below. For example: array = [20%,*,30%, 10%]
Given the following Java which is loaded into the database using loadjava: package grassie.example;
Given the example below, can someone please show me how this could be called?
Given the example source code below, is it possible for someone to see the
Given the XML/RDF example below taken from the W3C website, how can I access
When using downloaded R packages, such as tm, the given example usually loads an
Which static class initializes first if we have one more static classes in our
I followed a simple example as below. But compile failed. Could you please have
I have placed below the simplest example I could come up with to demonstrate

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.