Logo

Programming-Idioms

History of Idiom 189 > diff from v3 to v4

Edit summary for version 4 by programming-idioms.org:
[Python] Add Demo. Simplify predicate.

Version 3

2019-09-27, 13:07:21

Version 4

2019-09-27, 13:26:07

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements of list x that match the predicate P.

Idiom #189 Filter and transform list

Produce a new list y containing the result of function T applied to all elements of list x that match the predicate P.

Extra Keywords
map apply
Extra Keywords
map apply
Code
y = [T(i) for i in x if P(i,x)]
Code
y = [T(e) for e in x if P(e)]
Demo URL
http://pythonfiddle.com/idiom-189