Logo

Programming-Idioms

History of Idiom 57 > diff from v46 to v47

Edit summary for version 47 by sgdpk:
New Python implementation by user [sgdpk]

Version 46

2019-09-26, 15:52:41

Version 47

2019-09-27, 03:28:06

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering. Don't modify x in-place.

Code
y = [element for element in x if p(element)]
Comments bubble
List comprehensions tend to be more readable than filter function