[Tutor] Creating lists with 3 (later4) items occuring only once

Martin A. Brown martin at linux-ip.net
Mon Sep 21 20:16:29 CEST 2015

```Hello again Marcus,

> My task is to have lists containing 3 tuples, each tuple ocurring
> only once. In my code above I started off with 6 tuples ( = s) of
> which 20 lists (count) are produced containing each of the 6
> tuples multiple times.

Below, I'm confirming that there are 325 input "tuples".  I would,
however, call them pairs (since the term tuple has a different
meaning in Python).  If I were to turn one of your pairs 'ab' into a
tuple, I would call it ('a', 'b').  Anyway, here's confirmation on
your numbers (I don't think anybody has been doubting these numbers
that you keep repeating; I'm just confirming them):

>>> len([''.join(x) for x in itertools.combinations(string.ascii_lowercase, 2)])
325

Confirming that there are 20 combinations starting from 6 pairs
(N.B. you have 6 pairs in your code, although they are slightly
different than my 6 pairs):

>>> s = [''.join(x) for x in itertools.combinations('abcd',2)]
>>> len(s)
6
>>> len(list(itertools.combinations(s, 3)))
20

> Your code proposal uses dictionaries.  If I used dictionaries with
> all the 325 possible tuples I would have to do a lot of typing and
> not getting lists with 3 tuples in it.

Alan's code proposal was using dictionaries merely to count and
validate.  Essentially, all his code did was prove to you (and us)
that itertools.combinations() was doing what it advertises.

> Therefore, I try to write additional code for eliminating all
> lists which contain tuples occuring more than once. If I use all
> 325 tuples I would first get many thousand lists.
>
> So, I am stuck somehow and hope to have made my tasks clear.

The problem remains that none of us understands exactly what you
mean when you say duplicates.

If you use itertools.combinations(), no tuple produced will contain
a pair more than once.  So, you clearly have some other duplicate
detection criteria in mind.

In your first postings, you used single letters and built tuple
pairs.  Now, you are using concatenated string pairs.  This is
syntactic sugar (for most of us).  The real issue is that we do not
understand your needs for duplicate detection.

Several people (at least Oscar, Mark, Peter, Alan, Marc and I) have
attempted to infer which duplicates you are trying to remove and
even provide guidance on generic, known solutions to the problem
that you are posing (the Steiner system, for example).  Here are
some of the earlier replies:

https://mail.python.org/pipermail/tutor/2015-September/106692.html
https://mail.python.org/pipermail/tutor/2015-September/106705.html

In the following response you sent to the list,

https://mail.python.org/pipermail/tutor/2015-September/106685.html

you mentioned golfers and the passing of time, but you made no
further explanation of the rules for tossing duplicates.

Could you try again to explain what you mean by duplicate?

It's possible that once you better explain the rules of the system
you are trying to model, somebody can provide further assistance.

('ab', 'ac', 'bc'),
('ab', 'ac', 'bd'),
('ab', 'ac', 'cd'),
('ab', 'bc', 'bd'),
('ab', 'bc', 'cd'),
('ab', 'bd', 'cd'),
('ac', 'bc', 'bd'),
('ac', 'bc', 'cd'),
('ac', 'bd', 'cd'),
('bc', 'bd', 'cd')]

I've pasted above a small list of tuples (using your most recent
pair generation).  Could you annotate each tuple and explain why it
should be kept or thrown away?  That may help me (and any others who
are interested) understand what you are asking.

-Martin

>>>>> s = ['ab','ac','bc','ad','ae','de'] for startlist in
>>>>> itertools.combinations(s, 3):
>
>> How can I concatenate the 20 lists in oder to get one count for each of the items in s , for example 10 for 'ab'?
>
>
> If I understand you correctly, something like this:
>
> >>> for combo in it.combinations(counts.keys(),3):
> ...     for pair in combo:
> ...        counts[pair] += 1
> ...
> >>> counts
> {'ac': 10, 'ab': 10, 'ae': 10, 'ad': 10, 'bc': 10, 'de': 10}
>
> Is that what you want?
>
> --
> Alan G
> Author of the Learn to Program web site
> http://www.alan-g.me.uk/
> http://www.amazon.com/author/alan_gauld
> Follow my photo-blog on Flickr at:
> http://www.flickr.com/photos/alangauldphotos
>
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
>
> ---
> Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
> https://www.avast.com/antivirus
>
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor

--
Martin A. Brown
http://linux-ip.net/
```