Jump to content

Z12869: Difference between revisions

From Wikifunctions
No edit summary
 
protection for lists with elements of multiple types
Line 14: Line 14:
"Z61K1": "python"
"Z61K1": "python"
},
},
"Z16K2": "def Z12741(Z12741K1, Z12741K2):\n\tif len(Z12741K1) != len(Z12741K2):\n\t\treturn False\n\treturn sorted(Z12741K1) == sorted(Z12741K2)"
"Z16K2": "def Z12741(Z12741K1, Z12741K2):\r\n if len(Z12741K1) != len(Z12741K2):\r\n return False\r\n\r\n # Define a custom sorting function. It will sort elements first by type, then by value\r\n def custom_sort(element):\r\n return (str(type(element)), element)\r\n\r\n try:\r\n return sorted(Z12741K1, key=custom_sort) == sorted(Z12741K2, key=custom_sort)\r\n except TypeError:\r\n # If there is a TypeError while sorting, it means there were non-comparable types in the list\r\n return False"
}
}
},
},

Revision as of 05:00, 8 February 2024

This page displays in a limited way without JavaScript.