Why is the order of multiple `for` list comprehension the way it is?

前端 未结 2 463
天涯浪人
天涯浪人 2020-12-18 15:41

I know the right way to have multiple for in a nested list comprehension is as follows (Python 3):

lista = [[[1,2],[3],[4,5,6]],[[7],[8,9]]]

fl         


        
2条回答
  •  忘掉有多难
    2020-12-18 16:31

    Just remember the famous line from Casablanca: "Of all the gin joints in all the towns in all the world..." And then remember that the Python equivalent is backwards from that.

    [ginjoint for town in world for ginjoint in town] 
    

    Because who wants their programming language to sound like the greatest movie of all time?

提交回复
热议问题