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:
240
Nodes:
10 (0
/
10)
Uptime:
31:12:04
Calls:
1,451
Files:
3,349
Messages:
359,007
Synchronet Oneliners
Vintagegeek@rdbbs Fri Apr 19 05:10:04 2024 More INPUT STEPHANIE
Vintagegeek@rdbbs Sun Apr 21 16:10:32 2024 We need more Commercials
Vintagegeek@rdbbs Tue Apr 23 06:41:24 2024 Boss, the plane the plane
Ratthing@rdbbs Tue Apr 23 21:29:06 2024 hello from Texas!
Vintagegeek@rdbbs Wed Apr 24 06:18:54 2024 Greetings Lone Star State
Vintagegeek@rdbbs Fri Apr 26 05:27:11 2024 Running out of energy. Coffee Time