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
System Info
Sysop:
deepend
Location:
Calgary, Alberta
Users:
317
Nodes:
10 (0
/
10)
Uptime:
07:36:44
Calls:
2,633
Files:
6,386
D/L today:
52 files
(36,306K bytes)
Messages:
486,108
Synchronet Oneliners
Guest@rdbbs Thu Jul 30 19:09:46 2026 life finds a way
Vintagegeek@rdbbs Thu Aug 6 08:40:12 2026 Typhoon Dolphin
Vintagegeek@rdbbs Thu Aug 6 18:15:54 2026 You're The Quarterback
Vintagegeek@rdbbs Sun Aug 9 07:44:13 2026 Dammit, throw strikes, jeez
Vintagegeek@rdbbs Fri Aug 14 09:46:57 2026 Boom Boom Boom
Vintagegeek@rdbbs Fri Aug 21 04:44:35 2026 penny Penny penny