初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題466
def lower_and_remove_nonalpha(s):
return ”.join(c.lower() for c in s if c.isalpha())
text = “Hello World! 123”
print(lower_and_remove_nonalpha(text)) # ‘helloworld’
問題467
def are_lists_equal(lst1, lst2):
return len(lst1) == len(lst2) and sorted(lst1) == sorted(lst2)
list1 = [1, 2, 3]
list2 = [3, 2, 1]
print(are_lists_equal(list1, list2)) # True
問題468
def min_negative_even(lst):
neg_even = [x for x in lst if x < 0 and x % 2 == 0]
return min(neg_even) if neg_even else None
#<は半角記号に変換
numbers = [4, -2, -8, 7]
print(min_negative_even(numbers)) # -8



コメント