Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,940 questions

51,877 answers

573 users

How to create 3D list in Python

1 Answer

0 votes
lists = []

for k in range(3):
    lst = []
    for j in range(4):
        col = []
        for i in range(5):
            col.append(0)
        lst.append(col)
    lists.append(lst)

lists[0][0][0] = 1
lists[0][1][1] = 2

lists[1][2][0] = 3
lists[1][3][1] = 4

lists[2][2][1] = 5
lists[2][3][4] = 6

for k in range(3):
    print(lists[k])


'''
run:

[[1, 0, 0, 0, 0], [0, 2, 0, 0, 0], [0, 0, 0, 0, 0], [0, 0, 0, 0, 0]]
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [3, 0, 0, 0, 0], [0, 4, 0, 0, 0]]
[[0, 0, 0, 0, 0], [0, 0, 0, 0, 0], [0, 5, 0, 0, 0], [0, 0, 0, 0, 6]]

'''

 



answered Oct 26, 2018 by avibootz

Related questions

1 answer 143 views
2 answers 237 views
1 answer 99 views
1 answer 173 views
3 answers 160 views
160 views asked Apr 17, 2021 by avibootz
1 answer 154 views
...