Python formating all values in list of lists
<p>I am so sorry that I asking so silly question
but could you help me please format list of lists ("%.2f") for example:</p>

<pre><code>a=[[1.343465432, 7.423334343], [6.967997797, 4.5522577]]
</code></pre>

<p>I used:</p>

<pre><code>  for x in a:
     a = ["%.2f" % i for i in x]
     print (a)
</code></pre>

<p>OUT:</p>

<pre><code>['1.34', '7.42']
['6.97', '4.55']
</code></pre>

<p>But I would like to get my list of lists
OUT:</p>

<pre><code>[['1.34', '7.42'] ,['6.97', '4.55']]
</code></pre>

<p>A more general solution requires just a few lines. It recursively formats numbers, lists, lists of lists of any nesting depth.</p>

<pre><code>def fmt(data):
    if isinstance(data, list):
        return [fmt(x) for x in data]
    try:
        return "%.2f" % data
    except TypeError:
        return data


a=[[1.343465432, 7.423334343], [6.967997797, 4.5522577], [10, [20, 30]], 40] 
print(fmt(a))
# [['1.34', '7.42'], ['6.97', '4.55'], ['10.00', ['20.00', '30.00']], '40.00']
</code></pre>

python list format