From cosarara@cosarara@tilde.club to tilde.python on Wed Dec 22 09:56:19 2021
Run the following code:
a = a[0] = [0]
print(a)
Do you think it will error out on the first line? Can you explain how it works? Think about it, then read below for the answer:
Chained assignment in python takes the rightmost element and assigns
left to right, such that the statement boils down to:
tmp = [0]
a = tmp
a[0] = tmp
Thus creating a as a list of one element, that element being itself.
This is probably the most confusing and satisfyingly evil python trick I
know. Do you know other interesting tricks?
--- Synchronet 3.19a-Linux NewsLink 1.113
Who's Online
Recent Visitors
Deepend
Thu Mar 28 10:04:35 2024
from
Calgary, Ab
via
HTTP
System Info
Sysop:
deepend
Location:
Calgary, Alberta
Users:
239
Nodes:
10 (0
/
10)
Uptime:
73:47:26
Calls:
1,412
Files:
3,254
Messages:
354,259
Synchronet Oneliners
Vintagegeek@rdbbs Fri Feb 23 05:35:04 2024 I like the Color Options
Vintagegeek@rdbbs Tue Feb 27 11:30:35 2024 They Are Really Great
Vintagegeek@rdbbs Tue Mar 5 05:42:36 2024 Unclog the drain
Vintagegeek@rdbbs Thu Mar 14 06:28:57 2024 Something in the Water
Vintagegeek@rdbbs Tue Mar 19 09:58:25 2024 Congress - bunch of monkees throwing sh^t at each other