gave this to ChatGPT4, asked it to complete the function:<p><pre><code> len, print = print, len
def print_len(arg: list):
# put code here
</code></pre>
First try (body only):<p><pre><code> len(arg) # len is now print
</code></pre>
Second try after me telling it's wrong:<p><pre><code> print(arg) # print is now len
</code></pre>
Third try after me telling it's wrong:<p><pre><code> len(arg) # len now functions as print
print(arg) # print now functions as len
</code></pre>
It got the correct answer only when I asked it to first print what the function would look like without the swap, and then I asked it what it would look like with the swap.<p>EDIT: I tried again with:<p><pre><code> complete the function body:
len, print = print, len
def print_len(arg: list) -> None:
""" This function prints the length of the input list """
# put code here
</code></pre>
It gave the correct answer on the first try.