You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
In this example, a string containing Python code is compiled into a code object using`compile()`, and then executed with`exec()`. The function`hello_world()` defined in the string is then available to be called.
53
+
In this example, a string containing Python code is compiled into a code object using`compile()`, and then executed with`exec()`. The function`hello_world()` defined in the string is then available to be called.
Copy file name to clipboardExpand all lines: docs/builtin/filter.md
+6Lines changed: 6 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -46,3 +46,9 @@ The `filter()` function constructs an iterator from those elements of the iterab
46
46
```
47
47
48
48
In this example, the`is_even` function is defined to determine whether a number is even or not. The filter method takes`two arguments`: the`first argument` is the function to apply to each element of the list, and the`second argument` is the list to be filtered. The filter method returns an <router-linkto="/builtin/iter">iterator</router-link>, which is then converted to a list and stored in the even_numbers variable. The final output is the list of even numbers from the original list.
49
+
50
+
##See also
51
+
52
+
- <router-linkto="/builtin/map">map()</router-link>: Apply a function to every item of an iterable and return an iterator of the results.
53
+
- <router-linkto="/builtin/iter">iter()</router-link>: Return an iterator object.
54
+
- <router-linkto="/blog/python-comprehensions-step-by-step">List Comprehensions</router-link>: A concise way to create lists, often used as an alternative to`filter()`.