반응형
This Kata is intended as a small challenge for my students
All Star Code Challenge #18
Create a function that accepts 2 string arguments and returns an integer of the count of occurrences the 2nd argument is found in the first one.
If no occurrences can be found, a count of 0 should be returned.
("Hello", "o") ==> 1
("Hello", "l") ==> 2
("", "z") ==> 0
Notes:
- The first argument can be an empty string
- The second string argument will always be of length 1
Solution:
def str_count(string, letter):
func = lambda x: x == letter and True
return [func(i) for i in string].count(True)
반응형
'나는 이렇게 학습한다 > Algorithm & SQL' 카테고리의 다른 글
1014. Find Multiples of a Number (0) | 2022.10.14 |
---|---|
1013. Area or Perimeter (0) | 2022.10.13 |
1011. Square(n) Sum (0) | 2022.10.11 |
1010. Double Char (0) | 2022.10.10 |
1009. Surface Area and Volume of a Box (0) | 2022.10.10 |