AttributeError: 'tuple' object has no attribute 'sort'

Code in Free Course, " opencv-python-free-course-code", produces error as follows:

AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15804/465439247.py in
4
5 # Sort matches by score
----> 6 matches.sort(key=lambda x: x.distance, reverse=False)
7
8 # Remove not so good matches

AttributeError: ‘tuple’ object has no attribute ‘sort’

Need help resolving.

Code in Free Course, " opencv-python-free-course-code", produces error

can you link us to the resp. source code ?
there was indeed some recent python api change,
where lists (e.g. of DMatch) got changed to tuples

maybe a simple:

list(matches).sort(key=lambda x: x.distance, reverse=False)

does it already ?

I’d recommend

matches = sorted(matches, key=lambda x: x.distance)

because list(matches).sort() creates a list object without a variable referencing it, and the sort() returns nothing

This worked. Thanks for your help.

Thanks for your response. This seemed to function, i.e. no error, but the resultant Match keypoints were all over the place. This gave the right results :

matches = sorted(matches, key=lambda x: x.distance)