# [Tutor] problem solving with lists

Dennis Lee Bieber wlfraed at ix.netcom.com
Sat Mar 26 12:52:31 EDT 2022

```On Sat, 26 Mar 2022 10:25:54 +0100, <marcus.luetolf at bluewin.ch> declaimed
the following:

>1. in your 4th and  inner loop " select /p/ from (pg * g) players" what does
>(pg * g) mean ? the value for pg is 4 but g should initially be an empty
>list or set ???

My apologies... both of those should be changed...

(sg * ng)

That is: the size of each group times the number of groups determines how
many players are to be available for selection.

>    If I use combinations() I get 1820 lists or sets out of 16 players and
>sg = 4.
>2. in sets there is no order. If I use sets instead of lists how could I
>find/reject sets with equal pairings of elements ?

It is EASIER using sets.

set1 INTERSECT set2	=>	a set of only common elements

If the result is empty, there are no common elements (useful for filtering
the groups in each week, as no player is to appear more than once)

If the result has 2 or more elements, there are one or more common pairs
(useful for filtering current group against previous weeks)

https://docs.python.org/3/library/stdtypes.html#set-types-set-frozenset

Alternative notations:

set1.intersection(set2)
set1 & set2

Hmmm, I'd missed the .isdisjoint() method -- that replaces (consolidates)
testing if an intersection is empty; though may not save much in code...

if not set1.isdisjoint(set2):
vs
if set1 & set2:

--
Wulfraed                 Dennis Lee Bieber         AF6VN
wlfraed at ix.netcom.com    http://wlfraed.microdiversity.freeddns.org/

```