This is documented under Structural Pattern Matching

Like unpacking assignments, tuple and list patterns have exactly the same meaning and actually match arbitrary sequences. Technically, the subject must be a sequence. Therefore, an important exception is that patterns don’t match iterators. Also, to prevent a common mistake, sequence patterns don’t match strings.

and in PEP 635 -- Structural Pattern Matching: Motivation and Rationale

As in iterable unpacking, we do not distinguish between 'tuple' and 'list' notation. [a, b, c], (a, b, c) and a, b, c are all equivalent. While this means we have a redundant notation and checking specifically for lists or tuples requires more effort (e.g. case list([a, b, c])), we mimic iterable unpacking as much as possible.

Answer from user459872 on Stack Overflow
🌐
Plain English Westminster
benhoyt.com › writings › python-pattern-matching
Structural pattern matching in Python 3.10
To match on constants, they have to have a dot in them – so case Colors.RED works. In writing some of the code above I actually made this mistake: I wrote case ('commit' | 'tree' | 'blob', mode), expecting it to match if the tuple’s second item was equal to mode, but of course it would have set mode to the second item.
🌐
Python
peps.python.org › pep-0622
PEP 622 – Structural Pattern Matching | peps.python.org
Like unpacking assignment, both tuple-like and list-like syntax can be used, with identical semantics. Each element can be an arbitrary pattern; there may also be at most one *name pattern to catch all remaining items: match collection: case 1, [x, *others]: print("Got 1 and a nested sequence") case (1, x): print(f"Got 1 and {x}")
🌐
Python
peps.python.org › pep-0636
PEP 636 – Structural Pattern Matching: Tutorial | peps.python.org
Note the last block: the “variable name” _ acts as a wildcard and never fails to match. You can combine several literals in a single pattern using | (“or”): ... # point is an (x, y) tuple match point: case (0, 0): print("Origin") case (0, y): print(f"Y={y}") case (x, 0): print(f"X={x}") case (x, y): print(f"X={x}, Y={y}") case _: raise ValueError("Not a point")
🌐
Readthedocs
pc-python.readthedocs.io › en › latest › python_advanced › match_case.html
6. Match - Case — PC-Python
Python match-case statements can be used to check the types of something being passed in. In the code below, lists [ ], tuples ( ) and sets { } are distinguished.
🌐
Guru99
guru99.com › home › python › python tuple – pack, unpack, compare, slicing, delete, key
Python TUPLE – Pack, Unpack, Compare, Slicing, Delete, Key
August 12, 2024 - Tuple Matching in Python is a method of grouping the tuples by matching the second element in the tuples. It is achieved by using a dictionary by checking the second element in each tuple in python programming.
🌐
Python Engineer
python-engineer.com › posts › pattern-matching-python
Master Pattern Matching In Python 3.10 | All Options | - Python Engineer
# point is an (x, y) tuple match point: case (0, 0): print("Origin") case (0, y): print(f"Y={y}") case (x, 0): print(f"X={x}") case (x, y): print(f"X={x}, Y={y}") case _: raise ValueError("Not a point")
Find elsewhere
🌐
Scribd
scribd.com › document › 476206671 › What-is-Tuple-Matching-in-Python
What Is Tuple Matching in Python | PDF
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser
🌐
Turingtaco
turingtaco.com › pattern-matching-lists-and-dictionaries-in-python
Pattern Matching Lists and Dictionaries in Python
December 7, 2024 - Collectively, these features contribute ... tuples in Python operates under the same principles as lists, but we'll use parenthesis instead of square brackets....
🌐
GitHub
github.com › python › mypy › issues › 12364
`mypy` unable to narrow type of tuple elements in `case` clause in pattern matching · Issue #12364 · python/mypy
February 8, 2022 - I would expect mypy to derive the type from the case clause in the second function, just like it does in the first function. Knowing the first element of the matched tuple is of type MyClass it should allow for a call to .say_boo().
Published   Mar 16, 2022
Top answer
1 of 2
1

a good way to do this is to have a function that will extract the information you need from the tuple list i.e.

def get_address_info(address_data):
    address_number = None
    street_name_pre_directional = None
    street_name_post_directional = None

    for value, property_name in address_data:
        if property_name == "AddressNumber":
            address_number = value
        elif property_name == "StreetNamePreDirectional":
            street_name_pre_directional = value
        elif property_name == "StreetNamePostDirectional":
            street_name_post_directional = value

    return address_number, street_name_pre_directional, street_name_post_directional

that way you dont have to compare the items with each another, and the maintenance is easier now you can get the necessary data and compare them directly and determine whether some information is missing by checking whether None is present in the info

add1_info = get_address_info(add1)
add2_info = get_address_info(add2)
if add1_info  == add2_info and None not in add1_info and None not in add2_info :
    #do something...
2 of 2
1

(Apart from the issue @glibdud pointed out) The way to go, I think, is to use set.

s1 = set(address1)
s2 = set(address2)
common = s1.intersection(s2)

Of course you can use more set operations to determine whether the overlap is enough evidence of being similar, but we do not have that information on your data.

In this case, it will output:

s1.intersection(s2)
Out[31]: {('Lake', 'PlaceName'), ('MI', 'StateName'), ('town,', 'PlaceName')}

In the end, I get the feeling from the definition of the question where one of the two can contain multiple addresses that you want to know whether an address is listed in your address register. In that case instead of intersection you'll want to use s1.issuperset(s2) or s2.issubset(s1), which returns you a nice bool to work with.

s1.issuperset(s2)
>> False
🌐
Datamentor
datamentor.io › python › match-case
Python match...case Statement (With Examples)
plot1 = (0, 4) match plot1: case (4,0): print('on x-axis') case (0,4): print('on y-axis') case (0,0): print('center') # Output: on y-axis · In the above example, we have created a tuple named plot1 with values: 0 and 4.
🌐
Edureka Community
edureka.co › home › community › categories › python › how can i match tuple elements with list elements
How can I match tuple elements with list elements | Edureka Community
September 7, 2018 - I have a list of tuples named eagles like this eagles= [("NCMS000","NCMS000"),("NCFP000"," ... error What can I do? Any suggestion is appreciated.
🌐
Medium
medium.com › @ryk.kiel › unlocking-the-power-of-structural-pattern-matching-in-python-3-10-d432c9946a87
Unlocking the Power of Structural Pattern Matching in Python 3.10 | by Ryk Kiel | Medium
January 20, 2023 - The case case (x, y) is destructure the tuple and assigns the first value to the variable x and the second value to the variable y. If the match is successful, it prints "The point is at (3, 4)". In conclusion, Structural Pattern Matching is a powerful feature that allows for more concise and expressive code in Python.
🌐
Oregoom
oregoom.com › home › match in python
▷ Match in Python - Oregoom.com
October 28, 2024 - The match block compares datos with two patterns: a list with exactly two elements and a tuple with three elements. If the data matches either of those patterns, the corresponding block is executed.