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 7571777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:45:14+00:00 2026-05-30T15:45:14+00:00

I have a map which says maps a string to a function like :

  • 0

I have a map which says maps a string to a function like :

validator = {'first_name' : validate_str,
             'last_name' : validate_str,
             'phone' : validate_phone }

I need to call the corresponding validate function based on the type of value I have in the map that will be fed to me as input for e.g.

for name in elements:
    # Validate the value of this name in the input map using the function
    # input is the map that has the value for each of these fields
    # elements is a list of all fields used to loop through one input at a time
    if validator[name]( input[name] ) is False:
        # Throw validation error
    else:
        # Do something else

This works fine unless for this scenario I am not sure if it can be done:

The validate_str also checks if a given string is of desired max length.

def validate_str(str, max-len):
    # Throw error if len(str) > max-len

The max-len can differ based on the string, so I need to call validate_str for first_name with say 64 characters and last name with 256 characters.

I can use a different map to say that this field has this max_len, but is it possible for the validator map to have pointer to the validate_str function with the max-len argument preset based on the field?

something like:

validator = {'first_name' : validate_str(max-len=64),
             'last_name' : validate_str(max-len=256),
             'phone' : validate_phone }

then call it for validation like:

if validator[name]( str=input[name] ) is False:
    # The appropriate value for max-len goes with the function call and just the
    # str is appended to the argument list while invoking. 

This makes life easier so that we need not then remember again what fields will have the max-len sent along with it.

  • 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-05-30T15:45:15+00:00Added an answer on May 30, 2026 at 3:45 pm

    You could use lambda to create a function of one argument (the string being validated) but has the length defined within in:

    {'first-name':lambda x: validate-str( x, 64 ), ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my current C++-project I have an STL map which maps integer keys onto
I have a Map which is to be modified by several threads concurrently. There
I have made a map with jQuery which is split up in many regions,
I have a Map model, which defines the details for an ASCII-art map for
Is it preferred to have one depot with multiple folders which map to different
I have a bean which I map to the database using Hibernate. I'm using
I have the following hsqldb table, in which I map UUIDs to auto incremented
I have an App which launches the google Map App. The code is: UIApplication
I have a spring-hibernate application which is failing to map an object properly: basically
I have a view containing a UIWebView which is loading a google map (so

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.