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

2015-09-06 Thread Steven D'Aprano
Hello Marcus,

On Fri, Sep 04, 2015 at 04:28:10PM +0200, marcus lütolf wrote:

[...]
> I should probably tell you the real task are a series (maximum ~ 301) 
> lists in which real names of people are assigned to the items/letters 
> for 2 people(golfers) can be in the same list(flight) only once for an 
> extended period of time. The next step would be to assign compatible 
> and noncompatible attributes to the items/letters which will reduce 
> the maximum of possible lists(flights)

Sorry, that description doesn't help me understand your problem.

Perhaps you could show how to generate the pairs you want given (say) a 
small list of names. Let us call them A, B, C, D and E (five people), 
taken three at a time?

(1) Can you write out all the possible lists for n=3 (the maximum)?

Assuming order does not matter, I get ten lists:

A B C
A B D
A B E
A C D
A C E
A D E
B C D
B C E
B D E
C D E


(2) Can you show what you mean by "compatible and noncompatible 
attributes", and use them to "reduce the maximum of possible lists"? How 
do you decide which of the ten above are allowed and which are not?


-- 
Steve
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


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

2015-09-06 Thread Marc Tompkins
On Fri, Sep 4, 2015 at 7:28 AM, marcus lütolf 
wrote:

> I should probably tell you the real task are a series (maximum ~ 301)
> lists in which real names  of people are assigned to the items/letters for
> 2 people(golfers) can be in  the same list(flight)  only once for an
> extended period of time.
> The next step would be to assign compatible and noncompatible attributes
> to the items/letters which will reduce the maximum of possible
> lists(flights)
>
>
I came up with this (obviously it could be made shorter, but I thought it
would be clearer this way):

import string, itertools

def main():
validCombos = []
usedPairs = []
allCombos = itertools.combinations(string.ascii_lowercase, 3)
for combo in allCombos:
pair1 = (combo[0],combo[1])
pair2 = (combo[0],combo[2])
pair3 = (combo[1],combo[2])
if pair1 in usedPairs or pair2 in usedPairs or pair3 in usedPairs:
next
else:
usedPairs.append(pair1)
usedPairs.append(pair2)
usedPairs.append(pair3)
validCombos.append(combo)
print(validCombos)
print(len(validCombos))
if __name__ == '__main__':
main()


The resulting triplets seem to meet your criteria - but there are only 90
of them.  How confident are you about the number 301?
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor