初心者向けのPythonのプログラミング問題です。入門編としてチャレンジしてください。Pythonの正答例は以下になります。
問題445
def remove_duplicates(lst):
return list(set(lst))
numbers = [1, 2, 2, 3, 3, 4]
print(remove_duplicates(numbers)) # [1, 2, 3, 4]
問題446
def first_negative(lst):
for num in lst:
if num < 0:
return num
return None
#<は半角記号に変換
numbers = [1, 2, -3, 4]
print(first_negative(numbers)) # -3
問題447
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



コメント