擅长:python、mysql、java
<p>下面是@aw4lly答案的变体,它将在Python3中工作。在</p>
<pre><code>def myMin(lst):
smallest = None
for i in lst:
if isinstance(i, list):
i = myMin(i)
if smallest is None or i is not None and i < smallest:
smallest = i
return smallest
</code></pre>
<p>这可以处理任何类型的嵌套列表,包括部分或完全空的列表(对于我们的目的,空列表是指除了其他“空”列表之外没有成员的列表)。空列表返回<code>None</code>作为它们的最小值,这与Python的标准<code>min</code>函数不完全相同(但是它使递归变得更容易)。在</p>
^{pr2}$