Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python [a]*b means [a,a,...b times]

The [0] * x creates a list with x elements. So,
>>> [ 0 ] * 5
   gives [0,0,0,0,0]

******** warn:they all point to the same object.
This is cool for immutables like integers but a pain for things like lists.
>>> t = [[]] * 5
>>> t
[[], [], [], [], []]
>>> t[0].append(5)
>>> t
[[5], [5], [5], [5], [5]]
>>> 
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #python #means
ADD COMMENT
Topic
Name
1+4 =