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 convert a 3D list into a 2D list in Python

1 Answer

0 votes
lst_3d = [[[10, 18, 7, 23, 22, 30],
           [1, 13, 16, 15, 25, 6],
           [13, 26, 22, 14, 3, 6],
           [29, 10, 1, 6, 10, 20]],
          [[11, 15, 2, 29, 5, 20],  
           [7, 22, 26, 30, 23, 3],
           [5, 26, 17, 9, 24, 24],  
           [10, 7, 12, 11, 21, 16]], 
          [[30, 17, 13, 3, 13, 17],
           [6, 29, 3, 19, 11, 30],
           [17, 22, 6, 2, 24, 16],  
           [4, 24, 8, 26, 7, 7]]]
  
lst_2d = [element for n in lst_3d for element in n] 

print(lst_2d)

 
      
     
'''
run:

[[10, 18, 7, 23, 22, 30], 
 [1, 13, 16, 15, 25, 6], 
 [13, 26, 22, 14, 3, 6], 
 [29, 10, 1, 6, 10, 20], 
 [11, 15, 2, 29, 5, 20], 
 [7, 22, 26, 30, 23, 3], 
 [5, 26, 17, 9, 24, 24], 
 [10, 7, 12, 11, 21, 16], 
 [30, 17, 13, 3, 13, 17], 
 [6, 29, 3, 19, 11, 30], 
 [17, 22, 6, 2, 24, 16], 
 [4, 24, 8, 26, 7, 7]]
     
'''

 



answered Apr 3, 2020 by avibootz

Related questions

...