[Tutor] Creating lists with definite (n) items without repetitions

Mark Lawrence breamoreboy at yahoo.co.uk
Thu Sep 3 21:09:18 CEST 2015


On 03/09/2015 14:32, Marcus Lütolf wrote:
> dear pythonistats
> as a newcomber I want to create a set of lists containing n items, for
> example n = 3:  (['a','b','c'], ['a','d','e'].......).
> The sequence of items in each list should be different. If the letters
> 'a'........'z' are used and n = 3 there is a maximum of 301 lists.

The formula for combinations is n! / (r! * (n - r)!) = 26! / (3! * 23!) 
= 26 * 25 * 24 / (3 * 2 * 1) = 2600, the number given by Peter Otten in 
his earlier answer using itertools.combinations.

The number for permutations is n! / (n - k)! = 26! / 23! = 26 * 25 * 24 
= 15,600.

So what criteria are you using to give 301?

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence



More information about the Tutor mailing list