# 161. Lambda Functions in filter()

***

**Snippet 1: Filtering Even Numbers from a List**

```python
# List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# Filter even numbers using lambda function
even_numbers = list(filter(lambda x: x % 2 == 0, numbers))

print(f"Even numbers: {even_numbers}")
```

***

**Snippet 2: Filtering Odd Numbers from a List**

```python
# List of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9]

# Filter odd numbers using lambda function
odd_numbers = list(filter(lambda x: x % 2 != 0, numbers))

print(f"Odd numbers: {odd_numbers}")
```

***

**Snippet 3: Filtering Positive Numbers**

```python
# List of numbers
numbers = [-5, 3, 7, -2, 9, -8]

# Filter positive numbers using lambda function
positive_numbers = list(filter(lambda x: x > 0, numbers))

print(f"Positive numbers: {positive_numbers}")
```

***

**Snippet 4: Filtering Strings with Length Greater Than 3**

```python
# List of strings
words = ['apple', 'an', 'banana', 'kiwi', 'pear']

# Filter words with length greater than 3 using lambda function
long_words = list(filter(lambda word: len(word) > 3, words))

print(f"Words with length > 3: {long_words}")
```

***

**Snippet 5: Filtering Strings Starting with 'a'**

```python
# List of strings
words = ['apple', 'banana', 'avocado', 'grape', 'apricot']

# Filter words starting with 'a' using lambda function
words_starting_with_a = list(filter(lambda word: word.startswith('a'), words))

print(f"Words starting with 'a': {words_starting_with_a}")
```

***

**Snippet 6: Filtering Numbers Greater Than a Specific Value**

```python
# List of numbers
numbers = [1, 5, 8, 12, 15, 3, 6]

# Filter numbers greater than 10 using lambda function
greater_than_10 = list(filter(lambda x: x > 10, numbers))

print(f"Numbers greater than 10: {greater_than_10}")
```

***

**Snippet 7: Filtering Non-Empty Strings**

```python
# List of strings
words = ['', 'hello', '', 'world', 'Python', '']

# Filter non-empty strings using lambda function
non_empty_words = list(filter(lambda word: word != '', words))

print(f"Non-empty strings: {non_empty_words}")
```

***

**Snippet 8: Filtering Palindromes from a List of Words**

```python
# List of strings
words = ['madam', 'hello', 'racecar', 'world', 'level']

# Filter palindromes using lambda function
palindromes = list(filter(lambda word: word == word[::-1], words))

print(f"Palindromes: {palindromes}")
```

***

**Snippet 9: Filtering Numbers Divisible by Both 2 and 3**

```python
# List of numbers
numbers = [1, 2, 3, 6, 9, 12, 18, 20]

# Filter numbers divisible by both 2 and 3 using lambda function
divisible_by_2_and_3 = list(filter(lambda x: x % 2 == 0 and x % 3 == 0, numbers))

print(f"Numbers divisible by 2 and 3: {divisible_by_2_and_3}")
```

***

**Snippet 10: Filtering Even Length Words**

```python
# List of words
words = ['apple', 'banana', 'cherry', 'date', 'kiwi']

# Filter words with even length using lambda function
even_length_words = list(filter(lambda word: len(word) % 2 == 0, words))

print(f"Even length words: {even_length_words}")
```

***
