Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
---You will get 2 inputs 1st parameter is the no. of elements in the list and the 2nd parameter is the no. of lists.
the elements inside the list should start from 0 and end at n-1.


I need to get an output like this:

Example -

Input - main(8,3)

Output - [
[0,1,2,3,4,5,6,7],
[0,1,2,3,4,5,6,7],
[0,1,2,3,4,5,6,7],
]

What I have tried:

what i tried was:

def main(i,j):
m=[]
l=list(range(i))
m.append([l]*j)
return m
Posted
Updated 12-Mar-20 7:11am
Comments
OriginalGriff 12-Mar-20 13:01pm    
And?
What does it f=do that you didn't expect, or not do that you did?
What have you tried to find out why?
Where are you stuck?
What help do you need?

1 solution

Try this:
Python
def main(i,j):
    m=[]
    l=list(range(i))
    for count in range(j):
        m.append(l)
    return m

array = main(8, 3)
for x in array:
    print(x)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900