別の数で割り切れる数を見つけるPythonプログラム

Python

以下のプログラムでは、匿名(ラムダ)関数を内部で使用しています。 filter() リスト内の13で割り切れるすべての数値を検索する組み込み関数。

ソースコード

# Take a list of numbers
my_list = [12, 65, 54, 39, 102, 339, 221,]

# use anonymous function to filter
result = list(filter(lambda x: (x % 13 == 0), my_list))

# display the result
print("Numbers divisible by 13 are",result)

出力

Numbers divisible by 13 are [65, 39, 221]



Hope this helps!

Source link

コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です