Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6001567
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:51:10+00:00 2026-05-23T00:51:10+00:00

I have two lists (which may or may not be the same length). In

  • 0

I have two lists (which may or may not be the same length). In each list, are a series of tuples of two points (basically X, Y values).

I am comparing the two lists against each other to find two points with similar point values. I have tried list comprehension techniques, but it got really confusing with the nested tuples inside of the lists and I couldn’t get it to work.

Is this the best (fastest) way of doing this? I feel like there might be a more Pythonic way of doing this.

Say I have two lists:

pointPairA = [(2,1), (4,8)]
pointPairB = [(3,2), (10,2), (4,2)]

And then an empty list for storing the pairs and a tolerance value to store only matched pairs

matchedPairs = []
tolerance = 2

And then this loop that unpacks the tuples, compares the difference, and adds them to the matchedPairs list to indicate a match.

for pointPairA in pointPairListA:
    for pointPairB in pointPairListB:
        ## Assign the current X,Y values for each pair
        pointPairA_x, pointPairA_y = pointPairA
        pointPairB_x, pointPairB_x = pointPairB

        ## Get the difference of each set of points
        xDiff = abs(pointPairA_x - pointPairB_x)
        yDiff = abs(pointPairA1_y - pointPairB_y)

        if xDiff < tolerance and yDiff < tolerance:
            matchedPairs.append((pointPairA, pointPairB))

That would result in matchedPairs looking like this, with tuples of both point tuples inside:

[( (2,1), (3,2) ), ( (2,1), (4,2) )]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T00:51:11+00:00Added an answer on May 23, 2026 at 12:51 am

    Here pointpairA is the single list and pointpairB would be one of the list of 20k

    from collections import defaultdict
    from itertools import product
    
    pointPairA = [(2,1), (4,8)]
    pointPairB = [(3,2), (10,2), (4,2)]
    tolerance = 2
    
    dA = defaultdict(list)
    tolrange = range(-tolerance, tolerance+1)
    for pA, dx, dy in product(pointPairA, tolrange, tolrange):
        dA[pA[0]+dx,pA[1]+dy].append(pA)
    
    # you would have a loop here though the 20k lists
    matchedPairs = [(pA, pB) for pB in pointPairB for pA in dA[pB]]  
    
    print matchedPairs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two lists which are guaranteed to be the same length. I want
I have two unsorted lists and I need to produce another list which is
I have two lists of objects. Each list is already sorted by a property
I have two List's which I want to check for corresponding numbers. for example
I have two files which both contain a list of words. Is there an
I have a method which compares two objects and returns a list of all
I have two lists, each on different tabs (sub-sites) of the site. I would
I have two lists and I want to select items that are not in
We have two lists: a=['1','2','3','4'] b=['2','3','4','5'] How to get a list with elements that
Say I have two lists or arrays of strings. For example: list 1: a,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.