Creating a list in Python with multiple copies of a given object in a single line

前端 未结 6 1181
孤街浪徒
孤街浪徒 2020-12-03 04:56

Suppose I have a given Object (a string \"a\", a number - let\'s say 0, or a list [\'x\',\'y\'] )

I\'d like to create list containing many copies of thi

6条回答
  •  广开言路
    2020-12-03 05:24

    You could do something like

    x = 
    n = 
    L = [x for i in xrange(n)]
    

    Substitute range(n) for Python 3.

提交回复
热议问题