Python: Get numbers divisible by fifteen from a list using an anonymous function
Python Basic: Exercise-110 with Solution
Write a Python program to get numbers divisible by fifteen from a list using an anonymous function.
Sample Solution:-
num_list = [45, 55, 60, 37, 100, 105, 220]
# use anonymous function to filter
print("Numbers list :",num_list)
result = list(filter(lambda x: (x % 15 == 0), num_list))
print("Numbers divisible by 15 are",result)
=========== RESTART: F:/Python_APSC/py-ex-basic-110.py ===========
Numbers list : [45, 55, 60, 37, 100, 105, 220]
Numbers divisible by 15 are [45, 60, 105]
>>>
print("Please input a number list : ",end='')
numList = [int(x) for x in input().split(',')]
print("Numbers list :",numList)
result = list(filter(lambda x: (x % 15 == 0), numList))
print("Numbers divisible by 15 are",result)
======== RESTART: F:/Python_APSC/py-ex-basic-110.py ===========
Please input a number list : 35,45,60,25
Numbers list : [35, 45, 60, 25]
Numbers divisible by 15 are [45, 60]
>>>
print("Please input a number list : ",end='')
numList = [int(x) for x in input().split(',')]
print("Numbers list :",numList)
result = list(filter(lambda x: (x % 15 == 0), numList))
print("Numbers divisible by 15 are",result)
======== RESTART: F:/Python_APSC/py-ex-basic-110.py ===========
Please input a number list : 35,45,60,25
Numbers list : [35, 45, 60, 25]
Numbers divisible by 15 are [45, 60]
>>>
沒有留言:
張貼留言