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&#58;%m %d %b %y", time.localtime())) ] [ f(x) f, x in zip(flist, vlist) ] 

and want see is:

['<td>tue 22&#58;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&#58;%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&#58;%m %d %b %y", time.localtime(t)))] >>> [f(x) f, x in zip(flist, vlist)] ['<td>wed 05&#58;23 11 mar 09</td>'] 

Comments

Popular posts from this blog

c# - DetailsView in ASP.Net - How to add another column on the side/add a control in each row? -

javascript - firefox memory leak -

Trying to import CSV file to a SQL Server database using asp.net and c# - can't find what I'm missing -