3 ms·
I asked ChatGPT 3.5 to fix the code, modifying only the `print_len()` function. After some nudging, it came up with a very cheeky solution: def print_len(x
by DiogenesKynikos 3y ago
I asked ChatGPT 3.5 to fix the code, modifying only the `print_len()` function. After some nudging, it came up with a very cheeky solution:
def print_len(x):
"""Print the length of x"""
original_print = __builtins__.print
original_len = __builtins__.len
__builtins__.print = original_len
__builtins__.len = original_print
print(len(x))
__builtins__.print = original_print
__builtins__.len = original_len
However, trying to run this function caused my Python to crash (as in, my interpreter crashed entirely), for reasons I don't understand.
One other funny thing is that ChatGPT lectured me about how swapping `print` and `len` is bad programming practice:
> Please note that modifying built-in function names like this is generally not recommended, as it can lead to confusion and unexpected behavior in your code. It's advisable to use different variable names to avoid such issues.
Quite right, ChatGPT.