Created
March 23, 2017 16:38
-
-
Save niloy-barua/7c4b5c71914fb878dcc5e5763d232b56 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def toEvenOdd(numList): | |
""" | |
list: list containing number | |
return: two lists. first containing even numbers, second containing odd | |
numbers | |
""" | |
evenList=[] #will contain the even numbers after next iterative part | |
oddList=[] #will contain the odd numbers after next iterative part | |
for i in numList: | |
if i%2==0: | |
evenList.append(i) | |
else: | |
oddList.append(i) | |
return evenList, oddList |
uroybd
commented
Mar 23, 2017
•
এইটায় আমরা একটা is_even
function ব্যবহার করছি ফিল্টার করতে, ফাংশনটা রিইউজেবল, এইটুকুই সুবিধা:
def is_even(num):
return True if num % 2 == 0 else False
def to_even_odd_filter(num_list):
even = [i for i in num_list if is_even(i)]
odd = [i for i in num_list if not is_even(i)]
return even, odd
আমরা is_even
কে ফিল্টারে পাস করতে পারি। যেমন শুধু ইভেন নাম্বারগুলো পাওয়া যাবে এইভাবে:
num_list = [1, 2, 3, 4]
list(filter(is_even, num_list))
# output [2, 4]
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment