[f(x, your_set) for x in your_list]
, , ( Python 3).
(f(x, your_set) for x in your_list)
Edit:
, :
L = ['John', 'Jacob', 'Jingle all the way']
[foo(a, b=b) for a in L]
- map lambda. :
L2 = map(lambda arg: f(arg) + arg, L1)
L2 = map(lambda (x,y): x + y, L1)
L2 = map(lambda <arg>: <expression>, L1)
:
L2 = [f(arg) + arg for arg in L1]
L2 = [x + y for x, y in L1]
L2 = [<expression> for <arg> in L1]
Generator expressions are similar, but instead of a list, they return a lazy iterator and are written using parsers instead of square brackets. (And since mapPython 3 is modified so as not to return lists, its equivalent is a generator expression.) Sometimes a list is not needed, for example, when you want to do:
','.join(map(lambda x: x.upper(), L))
The concept of an equivalent list:
','.join([x.upper() for x in L])
But you really don't need a list, so you can just do:
','.join(x.upper() for x in L)