“Python -Filterfunktion” Code-Antworten

Python -Filter

lst = [1,2,3,4,5,6,7,8,9]
list(filter(lambda x:x%2 == 0, lst))
Gentle Gannet

Python -Filter ()

# Program to filter out only the even items from a list
my_list = [1, 5, 4, 6, 8, 11, 3, 12]

new_list = list(filter(lambda x: (x%2 == 0) , my_list))

print(new_list)
Busy Bird

Filterfunktion in Python

nums1 = [2,3,5,6,76,4,3,2]

def bada(num):
    return num>4 # bada(2) o/p: False, so wont return.. else anything above > value returns true hence filter function shows result  

filters = list(filter(bada, nums1))
print(filters)
 
(or) 
 
bads = list(filter(lambda x: x>4, nums1))
print(bads)
Tired Pasha rocks

Filterfunktion in Python

# filter is just filters things

my_list = [1, 2, 3, 4, 5, 6, 7]


def only_odd(item):
    return item % 2 == 1	# checks if it is odd or even


print(list(filter(only_odd, my_list)))
Tejas Naik

Python -Filter

number_list = range(-5, 5)
less_than_zero = list(filter(lambda x: x < 0, number_list))
print(less_than_zero)

# Output: [-5, -4, -3, -2, -1]

Python -Filterfunktion

numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 
def is_even(num):
    if num % 2 == 0:
        return True
         
even_numbers = filter(is_even, numbers)
 
print(list(even_numbers))
 
# Output
# [2, 4, 6, 8, 10]
Glorious Gnat

Ähnliche Antworten wie “Python -Filterfunktion”

Fragen ähnlich wie “Python -Filterfunktion”

Weitere verwandte Antworten zu “Python -Filterfunktion” auf Python

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen