limit - Combinations with limited repeats in Python -


i know how combinations of list in python itertools, if want limit amount of repeats?

so, if have [1, 2, 3, 4, 5]

but want limit combinations 3 repeats of each item (with fixed length of final list, 10):

[1, 1, 1, 2, 3, 3, 5, 5, 5, 4] [1, 2, 3, 3, 3, 4, 5, 5, 4, 4] [4, 4, 1, 1, 1, 5, 2, 2, 2, 3] 

and on. how do this?

this work:

import random  l = [1, 2, 3, 4, 5] l3 = l * 3 random.shuffle(l3) l3[:10] 

Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

android - Keyboard hides my half of edit-text and button below it even in scroll view -