write a program to print the values as given in output
input: [1, 2, 3, 4, [8, 7, 6, 5], 9, 10, 11, 12, [16, 15, 14, 13], 17, 18, 19, 20, [22, 22, 21, 20]]
output : 1,2,3,4,8,7,6,5,9,10,11,12,16,15,14,13,17,18,19,20,22,22,21,20
def Print(m, n, a):
k = 0
l = 0
while (k < m and l < n):
for i in range(l, n):
print(a[k][i], end=" ")
k += 1
for i in range(k, m):
print(a[i][n - 1], end=" ")
n -= 1
if (k < m):
for i in range(n - 1, (l - 1), -1):
print(a[m - 1][i], end=" ")
m -= 1
if (l < n):
for i in range(m - 1, k - 1, -1):
print(a[i][l], end=" ")
l += 1
x=[[1, 2, 3, 4], [8, 7, 6, 5], [9, 10, 11, 12], [16, 15, 14, 13], [17, 18, 19, 20], [22, 22, 21, 20]]
row = 6
col = 4
Print(row, col, x)
Comments
Leave a comment