Repeating elements in list comprehension

前端 未结 7 2272
走了就别回头了
走了就别回头了 2020-12-11 01:49

I have this list comprehension:

[[x,x] for x in range(3)]

which results in this list:

[[0, 0], [1, 1], [2, 2]]
相关标签:
7条回答
  • 2020-12-11 02:21
    >>> [i for i in range(3) for _ in range(2)]
    [0, 0, 1, 1, 2, 2]
    
    0 讨论(0)
提交回复
热议问题