replace empty elements in list of list

python

Solution

Using list comprehensions:

new_list = [[element or '0.00' for element in sublist] for sublist in big_list]

Problem

I am a newbie to python and I have a weird list of lists (for scientif experiments), which looks as follows: ``` aaa=[['2.2', '2.05', '', '2.2', '2', '', '2.2', '2', '2.1', '2.05', '2', '2', '', '', '2.15', '2', '2.05', '2.1', '', '', '', '', ''], ['2.2', '2.05', '', '2.2', '2', '', '2.2', '2', '2.1', '2.05', '2', '2', '', '', '2.15', '2', '2.05', '2.1', '', '', '', '', ''], ['2.2', '2.05', '', '2.2', '2', '', '2.2', '2', '2.1', '2.05', '2', '2', '', '', '2.15', '2', '2.05', '2.1', '', '', '', '', ''], ['3.3', '3.4', '', '3.25', '3.25', '', '3.5', '3.5', '3.4', '3.6', '3.5', '3.3', '', '', '3.2', '3.3', '3.4', '3.3', '', '', '', '', '']] ``` As you can see, some of these lists contain empty elements ''. I would like to replace the empty elements in the above list of list (potential size >1000) to "0.00" and I was wondering what is the most pythonic (one liner would be awesome) to achieve this. Obviously, I can iterate over the list using say i,j - but I was sure python had some itertools etc methods which could be very fast. Th

Original source