- In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.
- In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.
- In the third line, print
True
if it has any digits. Otherwise, printFalse
.In the third line, print
True
if it has any digits. Otherwise, printFalse
.
- In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.
- In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.
- In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.
- In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.
- In the third line, print
True
if it has any digits. Otherwise, printFalse
.
- In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.
- In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.
In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.In the third line, print
True
if it has any digits. Otherwise, printFalse
.In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.
Are function calls to scan an entire string for String validation better than looping through them in the main?based on multiple criteria
I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ..
In the first line, print True
if has any alphanumeric characters. Otherwise, print False
.
In the second line, print True
if has any alphabetical characters. Otherwise, print False
.
- In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.
In the third line, print True
if has any digits. Otherwise, print False
.
- In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.
In the fourth line, print True
if has any lowercase characters. Otherwise, print False
.
- In the third line, print
True
if it has any digits. Otherwise, printFalse
.
In the fifth line, print True
if has any uppercase characters. Otherwise, print False
.
- In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.
- In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.
Are function calls to scan an entire string for validation better than looping through them in the main?
I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ..
In the first line, print True
if has any alphanumeric characters. Otherwise, print False
.
In the second line, print True
if has any alphabetical characters. Otherwise, print False
.
In the third line, print True
if has any digits. Otherwise, print False
.
In the fourth line, print True
if has any lowercase characters. Otherwise, print False
.
In the fifth line, print True
if has any uppercase characters. Otherwise, print False
.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.
String validation based on multiple criteria
I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ...
- In the first line, print
True
if it has any alphanumeric characters. Otherwise, printFalse
.
- In the second line, print
True
if it has any alphabetical characters. Otherwise, printFalse
.
- In the third line, print
True
if it has any digits. Otherwise, printFalse
.
- In the fourth line, print
True
if it has any lowercase characters. Otherwise, printFalse
.
- In the fifth line, print
True
if has any uppercase characters. Otherwise, printFalse
.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.
I had me a code challenge and iI was thinking: is there a way to make this more efficient and short.? The challenge requires me to scan a string and ..
In the first line, print TrueTrue
if has any alphanumeric characters. Otherwise, print FalseFalse
.
In the second line, print TrueTrue
if has any alphabetical characters. Otherwise, print FalseFalse
.
In the third line, print TrueTrue
if has any digits. Otherwise, print FalseFalse
.
In the fourth line, print TrueTrue
if has any lowercase characters. Otherwise, print FalseFalse
.
In the fifth line, print TrueTrue
if has any uppercase characters. Otherwise, print FalseFalse
.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.
I had me a code challenge and i was thinking is there a way to make this more efficient and short. The challenge requires me to scan a string and
In the first line, print True if has any alphanumeric characters. Otherwise, print False.
In the second line, print True if has any alphabetical characters. Otherwise, print False.
In the third line, print True if has any digits. Otherwise, print False.
In the fourth line, print True if has any lowercase characters. Otherwise, print False.
In the fifth line, print True if has any uppercase characters. Otherwise, print False.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.
I had me a code challenge and I was thinking: is there a way to make this more efficient and short? The challenge requires me to scan a string and ..
In the first line, print True
if has any alphanumeric characters. Otherwise, print False
.
In the second line, print True
if has any alphabetical characters. Otherwise, print False
.
In the third line, print True
if has any digits. Otherwise, print False
.
In the fourth line, print True
if has any lowercase characters. Otherwise, print False
.
In the fifth line, print True
if has any uppercase characters. Otherwise, print False
.
Below is my approach :
def func_alnum(s):
for i in s:
if i.isalnum():
return True
return False
def func_isalpha(s):
for i in s:
if i.isalpha():
return True
return False
def func_isdigit(s):
for i in s:
if i.isdigit():
return True
return False
def func_islower(s):
for i in s:
if i.islower():
return True
return False
def func_isupper(s):
for i in s:
if i.isupper():
return True
return False
if __name__ == '__main__':
s = input()
s=list(s)
print(func_alnum(s))
print(func_isalpha(s))
print(func_isdigit(s))
print(func_islower(s))
print(func_isupper(s))
It feels like I made a mountain out of a molehill. But I would defer to your opinions on efficiency and shortness before I live with that opinion.