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
Guest
Mon Jul 13 08:47:08 2026
from
Copenhagen Dk
via
Telnet
Guest
Mon Jul 13 06:47:27 2026
from
Copenhagen Dk
via
Telnet
Vintagegeek
Sun Jul 12 08:01:34 2026
from
Swarthmore, Pa
via
Telnet
Ianroll
Sun Jul 12 07:19:38 2026
from
Bristol, Uk
via
Telnet
System Info
Sysop:
deepend
Location:
Calgary, Alberta
Users:
316
Nodes:
10 (0
/
10)
Uptime:
00:07:16
Calls:
2,581
Calls today:
2
Files:
6,216
D/L today:
72 files
(22,992K bytes)
Messages:
480,216
Synchronet Oneliners
Regen@rdbbs Tue Jun 9 09:36:17 2026 Knowledge is Good
Vintagegeek@rdbbs Wed Jun 10 15:01:58 2026 Hey Crazy Man. Do a little dance...
Vintagegeek@rdbbs Thu Jun 11 10:12:20 2026 Let the dogs out !!
Vintagegeek@rdbbs Thu Jun 25 19:54:33 2026 The Discovery of Witches
Vintagegeek@rdbbs Sun Jul 5 10:02:56 2026 The Core
Ianroll@rdbbs Sun Jul 12 07:18:14 2026 Upwards forever!