美文网首页
python 列表解析

python 列表解析

作者: CV_lsc | 来源:发表于2018-06-23 11:01 被阅读0次

    python 的列表解析提供了一种简洁的表达方式,通过一个例子了解一下。

    flattened = []
    for row in matrix:
        for n in row:
            flattened.append(n)
    
    flattened = [n for row in matrix for n in row]
    

    执行语句在前,条件语句按顺序敲就行了。
    参考:http://codingpy.com/article/python-list-comprehensions-explained-visually/

    相关文章

      网友评论

          本文标题:python 列表解析

          本文链接:https://www.haomeiwen.com/subject/fueryftx.html