# [Tutor] overlapping tuples

Richard Damon Richard at Damon-Family.org
Sat Feb 29 06:39:05 EST 2020

```On 2/28/20 8:36 PM, Narasimharao Nelluri wrote:
> Thanks Mats for your inputs.  overlap means if two numbers share across two
> tuples For Ex  if we take two tuples (1,20) and (15,20)  there is a
> over lap because 15,16,17,18,19,20  numbers are sharing between these
> two sets. Sets may not solve the issue because sets will
> eliminate duplicate elements in a given data structure. Here we are
> finding all the over lapping tuples  in a given list of tuples.
>
> Thanks
> Narasimha.

I think wat Mats was pointing out was that there is a lot of apparently
assumed knowledge about the problem, i.e. a lack of a formal statement
of what you are trying to do.

My understanding is as follows:

We are given a List of 2 element Tuples (a, b) each representing a
closed interval (inclusive of the end points) where the tuple (a, b)
represents all the values x such that a <= x <= b.

We want to find all the tuples in the list that represent ranges that
overlap with another tuple in the list.

I think what we still need is a better definition of what the output is
you want. Do you want a list of the tuples that participate in the
overlap (which is my first understanding of the problem) or do you want
the just a list of the ranges of overlap?

Details in the problem statement have great impact on the details of the
solution.

Is it allowed for a given range to be repeated? (Your example says Yes)

If a given range overlaps multiple other ranges, should it be listed
once or once per overlap?

list3 = [(1,10),(15,20),(1,10),(1,10),(101,110)]
tuple_overlap(list3)

in the first case it should return [(1, 10), (1, 10), (1, 10)] as (1,
10) occurs 3 times

in the second case it should probably return [{1, 10), (1, 10), (1, 10),
(1, 10), (1, 10), (1, 10)] as you have 3 tuples (1, 10) and each one
overlaps with 2 other tuples.

Both of these options need a bit more work in your program to handle,
and it makes a big difference as to which one you want.

This goes back to one of the basic principles of programming, makes sure
you have (and give to others) a good problem definition, and be prepared
as you move along to come up with more questions that need answers.
Short English statements may SEEM to be enough, but often are missing
details and have assumptions in definitions that need to be answered,

--

Richard Damon

```