GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • w3resource
  • Front End
  • HTML
  • CSS
  • JavaScript
  • HTML5
  • Schema.org
  • php.js
  • Twitter Bootstrap
  • Responsive Web Design tutorial
  • Zurb Foundation 3 tutorials
  • Pure CSS
  • HTML5 Canvas
  • JavaScript Course

This view

  • Original page
  • New address

GeezerVison is showing www.w3resource.com — Python: Check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda - w3resource

Python: Check whether a given string has a capital letter, a lower case letter, a number and specified length using lambda

Last update on July 12 2025 13:04:58 (UTC/GMT +8 hours)


33. Password Checker Lambda

Write a Python program to check whether a given string contains a capital letter, a lower case letter, a number and a minimum length using lambda.

Sample Solution:

Python Code :

# Define a function 'check_string' that takes a string 'str1' as input
def check_string(str1):
    # Define a list 'messg' containing lambda functions with string validation conditions
    messg = [
        lambda str1: any(x.isupper() for x in str1) or 'String must have 1 upper case character.',
        lambda str1: any(x.islower() for x in str1) or 'String must have 1 lower case character.',
        lambda str1: any(x.isdigit() for x in str1) or 'String must have 1 number.',
        lambda str1: len(str1) >= 7 or 'String length should be at least 8.',
    ]
    
    # Generate a list 'result' by evaluating each lambda function in 'messg' for the input string 'str1'
    result = [x for x in [i(str1) for i in messg] if x != True]
    
    # Check if 'result' list is empty (all validation conditions are met)
    if not result:
        # If 'result' is empty, append 'Valid string.' indicating the string passes all validations
        result.append('Valid string.')
    
    # Return the 'result' list containing validation messages or 'Valid string.' if the string is valid
    return result    

# Get user input for a string 's'
s = input("Input the string: ")

# Print the result of string validation by calling the 'check_string' function with input 's'
print(check_string(s)) 

Sample Output:

Input the string:  W3resource
['Valid string.']

For more Practice: Solve these Related Problems:

  • Write a Python program to validate if a string contains at least one special character, one number, and both uppercase and lowercase letters using lambda.
  • Write a Python program to check if a string contains no whitespace, includes at least one digit, and at least one uppercase letter using lambda.
  • Write a Python program to verify if a string qualifies as a strong password (uppercase, lowercase, digit, special character, minimum length 8) using lambda.
  • Write a Python program to check if a string contains exactly two uppercase letters, three lowercase letters, and one digit using lambda.

Go to:

  • Python Lambda Exercises Home ↩
  • Python Exercises Home ↩

Previous: Write a Python program to count float number in a given mixed list using lambda.
Next: Write a Python program to filter the height and width of students, which are stored in a dictionary using lambda.

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.


  • Daily Coding Challenges & Projects
  • Weekly Trends and Language Statistics



You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.