2018年1月11日 星期四

Python: Get numbers divisible by fifteen from a list using an anonymous function

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]

>>> 


沒有留言:

張貼留言

Messaging API作為替代方案

  LINE超好用功能要沒了!LINE Notify明年3月底終止服務,有什麼替代方案? LINE Notify將於2025年3月31日結束服務,官方建議改用Messaging API作為替代方案。 //CHANNEL_ACCESS_TOKEN = 'Messaging ...