DEV Community

Discussion on: Daily Challenge #219 - Compare Strings

Collapse
 
vidit1999 profile image
Vidit Sarkar

Python one liner,

strCount = lambda str1, str2: len(str1) and len(str2) and str1.count(str2)

Output,

print(strCount('Hello', 'o')) # output -> 1
print(strCount('Hello', 'l')) # output -> 2
print(strCount('', 'z')) # output -> 0
print(strCount('oh goodness gracious', 'o')) # output -> 4
print(strCount('Hello', '')) # output -> 0
print(strCount('howdy, pardner', 'd')) # output -> 2
print(strCount('Incumbent President', 'e')) # output -> 3
print(strCount('', '')) # output -> 0