1
List = [[10,17],[13,15],[13,17]]

for x in list:
    x_list = x_list + [x[0]]
    y_list = y_list + [x[1]]

Result:

x_list = [10, 13, 13]
y_list = [17, 15, 17]

This is what I did to separate the values. How do I check if there is an overlap in x_list or y_list?

UCYT5040
  • 367
  • 3
  • 15
Ya3goobs
  • 77
  • 1
  • 1
  • 5

1 Answers1

2

Use collections.Counter to count duplicates (i.e overlaps) as follows:

from collections import Counter

List = [[10,17],[13,15],[13,17]]

x_list, y_list = list(zip(*List))

overlaps_x = [e for e, c in Counter(x_list).items() if c > 1]
overlaps_y = [e for e, c in Counter(y_list).items() if c > 1]

print(overlaps_x)
print(overlaps_y)

Output

[13]
[17]

The idea is to first count the items and then output those elements with count greater than 1.

Dani Mesejo
  • 61,499
  • 6
  • 49
  • 76