sharing/swapping items between lists

Aaron Brady castironpi at gmail.com
Tue Apr 14 11:30:05 CEST 2009


On Apr 13, 11:52 pm, Aaron Brady <castiro... at gmail.com> wrote:
> On Apr 13, 10:04 am, Ross <ross.j... at gmail.com> wrote:
>
>
>
> > On Apr 11, 1:10 pm, a... at pythoncraft.com (Aahz) wrote:
>
> > > In article <4fd78ac3-ba83-456b-b768-3a0043548... at f19g2000vbf.googlegroups.com>,
>
> > > Ross  <ross.j... at gmail.com> wrote:
>
> > > >I'm trying to design an iterator that produces two lists. The first
> > > >list will be a list of unique pairings and the second will be a list
> > > >of items that weren't used in the first list. After each round, the
> > > >items that weren't used in the round before will get put back in and
> > > >the second list will be populated with unique items.
>
> > > How do you specify what goes into the first list?  Based on your
> > > description, I would have expected that the output from the first
> > > iteration would be
>
> > > ( [(1,2),(3,4),(5,6)], [7,8] )
>
> > > Regardless of the actual algorithm, if you are returning items one at a
> > > time and maintaining state in a computation, you probably want to use a
> > > generator.
> > > --
> > > Aahz (a... at pythoncraft.com)           <*>        http://www.pythoncraft.com/
>
> > > Why is this newsgroup different from all other newsgroups?
>
> > I'm sorry...my example was probably a bad one. A better example of
> > output I would like would be something like [[1,2],[3,4],[5,6]] and
> > then for the leftovers list [7,8,9,10 etc]. What I'm trying to do is
> > produce some sort of round robin algorithm for tennis that is
> > constrained by the number of courts available each week. So if there
> > are only 3 courts available for a singles league and 10 people have
> > signed up, 4 players will have a bye each week. I want my algorithm to
> > produce unique matchups each week and also give each player the same
> > angle?
>
> Take 3 people, 1 court.
snip

> Then, you need to arrange it so the player with most court time
> has at most one more match than the player with the least court time,
> after each week.

This is the difficult constraint to satisfy.

> Do you need to account for newcomers after the rotation has started,
> departers, favorites, skill, etc.?

This problem was actually more difficult than I gave it credit for.

The problem first shows up in 6 players 2 courts:

abcd
efac
bd EF!

Here, E and F are playing eachother twice in a row, although everyone
is getting the right number of games as early as possible.  It would
take some clever foresight, backtracing, or recognition to mix it up
better.  <attempted handoff>



More information about the Python-list mailing list