Internet & Web Application

Python List Duplication

> h = [[1,2]] * 2
> h
[[1,2],[1,2]]
> h[0][0] = 9
[[9,2],[9,2]]

> h = [ list([1,2] for i in xrange(2) ]
> h
[[1,2], [1,2]]
> h[0][0] = 9
[[9,2], [1,2]]

Advertisements
มาตรฐาน

ใส่ความเห็น

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s