+ 4

Challenge : print all the possible way to split a list in k chunks

you have 1 list [1,2,3,4,5,6] and a number k(3 for example). Your code need to print all the ways to split l in k chunks (20 ways in the example) Make a function using a list l and a number k as inputs, and returns a list, each element of this list being a way to cut l in k pieces. Bonus for one liners !

20th Jan 2018, 2:31 PM
VcC
VcC - avatar
9 Answers
+ 8
I think Kuba got it, but @Kuba can you change it so that the program prints according to user input?
20th Jan 2018, 4:22 PM
Cool Codin
Cool Codin - avatar
+ 7
I just assumed empty lists count, too: https://code.sololearn.com/cTZyOlsEo2pu/?ref=app
20th Jan 2018, 4:08 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 7
Aha, okay then. Gimme some time.
20th Jan 2018, 4:28 PM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
+ 6
@VcC Thanks! I didn't have the time yesterday and can't quite think of a way to put it into a one-liner (I know it's possible, but would become unwieldy), so here's my try: https://code.sololearn.com/cD2Lx1qi5ptQ/?ref=app
21st Jan 2018, 9:51 AM
Kuba SiekierzyƄski
Kuba SiekierzyƄski - avatar
21st Jan 2018, 1:15 PM
VcC
VcC - avatar
+ 2
cool coding : you need to split the list in k chunks, not just select k elemnts in the list !
20th Jan 2018, 3:10 PM
VcC
VcC - avatar
+ 2
@kuba congrats for your 100th code here by the way !
20th Jan 2018, 5:09 PM
VcC
VcC - avatar
+ 1
kuba good but the challenge is a code doing tjis for any k
20th Jan 2018, 4:24 PM
VcC
VcC - avatar
0
@kuba can you do a Oneliner and onehourer ?
20th Jan 2018, 4:41 PM
VcC
VcC - avatar