Create list | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Create list

Hi everybody.How can I do this. List=[1,2,3,4,5,6,7,8,9,10,11,12......,99,100] a=int(input("how many list do you need?")) b=int(input ("how many random choice do u need in 1 list?")) If answers are for example a=4 b=3 I should randomly make 4 lists and will be 3 numbers each And need to show results like this List1:5,36,24 List2:3,56,43 List3:24,87,4 List4:77,21,59 Thanx in advance for your helps

8th Jan 2019, 6:04 PM
Art
8 Answers
+ 2
You could return a list of lists Just create a new list outside both for loops and append each list to it and at the end return it. Or you can return a generator like I did from random import randint def getLists(a, b): for c in range(0, a): ls = [] for d in range(0, b): ls.append(randint(0, 100)) yield ls a=int(input("how many list do you need?")) b=int(input ("how many random choice do u need in 1 list?")) lists = getLists(a,b) for ls in lists: print(ls)
8th Jan 2019, 6:25 PM
Toni Isotalo
Toni Isotalo - avatar
+ 2
Ok, I think I misunderstood your question. I've changed my code
8th Jan 2019, 7:46 PM
Anna
Anna - avatar
+ 1
Its not doing what I need its writing 2 lists, one is 1 to 100 and the other one is 3 numbers from first list
8th Jan 2019, 7:41 PM
Art
+ 1
Thanx Anna I adjust it as my requ. and working perfect
8th Jan 2019, 8:20 PM
Art
0
Thank you for your answer thats working good enough but I need to write lists one by one in multi lines and they are going to have a new list name like list1,list2 etc
8th Jan 2019, 6:41 PM
Art
0
Thanx Anna,sorry but its not working
8th Jan 2019, 7:25 PM
Art
0
How is it not working?
8th Jan 2019, 7:34 PM
Anna
Anna - avatar