初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題463
def count_multiple_chars(s, chars):
return c: s.count(c) for c in chars
text = “hello world”
chars = [‘l’, ‘o’, ‘h’]
print(count_multiple_chars(text, chars)) # ‘l’: 3, ‘o’: 2, ‘h’: 1
問題464
def all_of_type(lst, t):
return all(isinstance(x, t) for x in lst)
numbers = [1, 2, 3]
print(all_of_type(numbers, int)) # True
words = [“a”, “b”, 3]
print(all_of_type(words, str)) # False
問題465
def last_vowel(s):
vowels = ‘aeiouAEIOU’
for c in reversed(s):
if c in vowels:
return c
return None
text = “hello world”
print(last_vowel(text)) # ‘o’



コメント