Preface: I realized this is just me being obsessed with making something more pythonic.
I have a list of lists like such:
L = [[1,'',3,''],[1,2,'',4],[1,2,3,''],['',2,3,4]]
I need to replace ONLY the 4th element with the number 4 IF it is ' '.
This can be achieved with a simple for loop:
for row in L:
if row[3] =='':
row[3] = 4
How can I achieve this through a nested list comprehension?
My best attempt is the following, but it results in a list of lists that have all values of ' ' replaced with 4, rather than the specific element.
L = [[4 if x=='' else x for x in y] for y in L]