
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Program to Create 3D List
3D list means 3D array. In this program we create 3D array with integer elements.
Example
Input: 3× 3 × 2 [[1,1,1],[2,2,2],[3,3,3]], [[4,4,4],[5,5,5],[6,6,6]]
Algorithm
Step 1: given the order of 3D list. Step 2: using for loop we create list and print data.
Example Code
# Python program to created 3D list import pprint def print3D(i, j, k): lst = [[ ['*' for cc1 in range(i)] for cc2 in range(j)] for r in range(k)] return lst # Driver Code c1 = 3 c2 = 2 r = 2 # used the pretty printed function pprint.pprint(print3D(c1, c2, r))
Output
[[['*', '*', '*'], ['*', '*', '*']], [['*', '*', '*'], ['*', '*', '*']]]
Advertisements