|
3 | 3 | # list comprehension, deep and shallow copy methods in Python.
|
4 | 4 | # The project can be performed on Jupyter Notebook or Google Colab.
|
5 | 5 |
|
6 | | -#take input without using library ast |
| 6 | +#take input without using library ast |
7 | 7 | in_str=input()
|
8 | | -#as the input is in the form --> m,n where m is number of rows and n is number of columns, so we will split it using comma as separator |
| 8 | + |
| 9 | +# as the input is in the form --> m,n where m is number of rows and n is number of columns, so we will split it using comma as separator |
9 | 10 | in_str=in_str.split(',')
|
| 11 | + |
10 | 12 | # number of rows : m
|
11 | 13 | m=int(in_str[0])
|
| 14 | + |
12 | 15 | # number of columns : n
|
13 | 16 | n=int(in_str[1])
|
14 | 17 |
|
15 | | -#make a list with n zeroes |
| 18 | +#make a list with n zeroes |
16 | 19 | final=[0]*n
|
17 | 20 |
|
18 | | -#make a matrix of m such lists using list comprehensions |
| 21 | +#make a matrix of m such lists using list comprehensions |
19 | 22 | final=[list(final) for i in range(m)]
|
20 | 23 |
|
21 | 24 | for i in range(m):
|
22 | 25 | for j in range(n):
|
23 | 26 | if i==0 or j==0 or i==m-1 or j==n-1:
|
24 | | - final[i][j]=1 #changing the list without any copy method |
| 27 | + final[i][j]=1 #changing the list without any copy method |
25 | 28 |
|
26 | | -#print in the fashion as shown in Sample output |
| 29 | +#print in the fashion as shown in Sample output |
27 | 30 | for i in final:
|
28 | 31 | print(i)
|
29 | 32 |
|
|
0 commit comments