do this with list comp?
jdhunter at ace.bsd.uchicago.edu
Fri Dec 12 17:46:58 CET 2003
I want to replace all empty fields in a CSV line with 'NULL'.
Here is a brute force way
ret = 
for s in line.split(','):
if not len(s): ret.append('NULL')
line = 'John,Bill,,,Fred'
# ['John', 'Bill', 'NULL', 'NULL', 'Fred']
I am wondering if there is a way to do it with list comprehensions. I
know how I would do it with a ternary operator.....
More information about the Python-list