Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

gfg placement course

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: #gfg #placement
ADD COMMENT
Topic
Name
6+8 =