python - Multiple operations in a List Comprehension -
say this:
vlist=[1236745404] flist=[ "<td>{}</td>".format ] [ f(x) f, x in zip(flist, vlist) ] but want convert integer time string feeding multiple process stream.
pseudocode:
flist=[ "<td>{}</td>".format(time.strftime("%a %h:%m %d %b %y", time.localtime())) ] [ f(x) f, x in zip(flist, vlist) ] and want see is:
['<td>tue 22:23 10 mar 09</td>'] is list comprehension variable input limited 1 operation, or can output passed downstream?
your 2 cases quite different; in first have callable (str.format) in second built complete string.
you'd need create callable second option too; in case lambda work:
flist=[lambda t: "<td>{}</td>".format(time.strftime("%a %h:%m %d %b %y", time.localtime(t)))] this list 1 callable, lambda accepts 1 argument t, , returns result of full expression t passed time.localtime() formatted using time.strftime passed str.format().
demo:
>>> import time >>> vlist=[1236745404] >>> flist=[lambda t: "<td>{}</td>".format(time.strftime("%a %h:%m %d %b %y", time.localtime(t)))] >>> [f(x) f, x in zip(flist, vlist)] ['<td>wed 05:23 11 mar 09</td>']
Comments
Post a Comment