【python】sorted函数出现TypeError: ‘<‘ not supported between instances of ‘str‘ and ‘int‘

 

1. Problem

The following code:

self.cams = sorted(list(cam_set))

 Even if the int or str type conversion has been performed, the following error still occurs:

TypeError: '<' not supported between instances of 'str' and 'int'

2. Modify

Reference: https://stackoverflow.com/questions/46433451/getting-a-typeerror-not-supported-between-instances-of-int-and-str-w

self.cams = sorted(list(cam_set), key=lambda x: str(x))

 

Guess you like

Origin blog.csdn.net/qq_35975447/article/details/112567277