- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to validate string has few selected type of characters or not
Suppose we have a string s. We have to check whether the string contains the following or not.
Numbers
Lowercase letters
Uppercase letters
Note − There may be some other symbols, but these three must be there
So, if the input is like s = "p25KDs", then the output will be True
To solve this, we will follow these steps −
- arr := an array of size 3 and fill with False
- for each character c in s, do
- if c is alphanumeric, then
- arr[0] := True
- if c is in lowercase, then
- arr[1] := True
- if c is in uppercase, then
- arr[2] := True
- if c is alphanumeric, then
- return true when all items of arr are true
Example
Let us see the following implementation to get better understanding
def solve(s): arr = [False]*3 for c in s: if c.isalnum(): arr[0] = True if c.islower(): arr[1] = True if c.isupper(): arr[2] = True return all(arr) s = "p25KDs" print(solve(s))
Input
"p25KDs"
Output
True
- Related Articles
- Program to check string is palindrome with lowercase characters or not in Python
- Program to validate a sudoku grid is solvable or not in Python
- Program to check if binary string has at most one segment of ones or not using Python
- Program to check whether we can make k palindromes from given string characters or not in Python?
- Program to check we can replace characters to make a string to another string or not in C++
- Program to check string contains consecutively descending string or not in Python
- Program to check the string is repeating string or not in Python
- Check if string follows order of characters defined by a pattern or not in Python
- C# program to determine if a string has all unique characters
- Switching positions of selected characters in a string in JavaScript
- Python program to check if the string is empty or not
- Python program to check if a string is palindrome or not
- Program to check a string is palindrome or not in Python
- Program to check given string is pangram or not in Python
- Program to check given string is anagram of palindromic or not in Python

Advertisements