Mar-29-2020, 05:18 AM
whats wrong with my code?
i cant get the desired output
i cant get the desired output
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
list1 = [] list2 = [] num = [ 1 , 2 , 3 , 4 , 5 , 6 ] while ( True ): if ( len (list2)< = 2 ): # generating numbers n = random.choice(num) list1.append(n) list1.sort() num.remove(n) if ( len (list1) = = 3 ): # appending to list if it has 3 elements list2.append(list1) num = [ 1 , 2 , 3 , 4 , 5 , 6 ] #declaring num list again else : print ( "no" ) break print ( "list2" ,list2) # printing 3 elements in format [[x,x,x],[x,x,x],[x,x,x]] <=== desired output |