Formatting Results so that They Can be Nicely Imported into a Spreadsheet.
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Sun Aug 12 14:17:28 EDT 2007
En Sun, 05 Aug 2007 06:06:54 -0300, SMERSH009 <SMERSH009X at gmail.com>
escribió:
> The only question that remains for me--and this is just for my
> knowledge-- what does the "if i" mean in this code snippet?
> f = [i.split() for i in d if i]
> How is it helpful to leave a dangling "if i"? Why not just f =
> [i.split() for i in d]?
`if i` means `if i is considered true`. In this case we are talking about
strings: "" is false and all other strings are true. So this is a way to
say `if i is not the empty string`, effectively filtering out empty lines.
Perhaps using more meaningful names for variables makes the code more
clear:
exploded_lines = [line.split() for line in lines if line]
--
Gabriel Genellina
More information about the Python-list
mailing list