Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 12111

How to append an object to multi-dimension list [duplicate]

$
0
0

I want to make a list like [ ['a'] , [] , [] , [] ]. I tried this code:

n = input()array = [[]]*narray[0].append('a')print array

But instead I get a wrong result:

[ ['a'], ['a'], ['a'], ['a'] ] #  <- wrong list

Why does this happen, and how can I fix it?


Viewing all articles
Browse latest Browse all 12111

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>