x, = y (???)
kj
socyl at 987jk.com.invalid
Fri Jul 18 11:49:49 EDT 2008
In <BZr*yX+hs at news.chiark.greenend.org.uk> Matthew Woodcraft <mattheww at chiark.greenend.org.uk> writes:
>kj wrote:
>> I still don't get it. If we write
>>
>> y = 'Y'
>> x, = y
>>
>> what's the difference now between x and y? And if there's no
>> difference, what's the point of performing such "unpacking"?
>If y really is is a string, I think it's likely that the line you came
>across was a typo.
OK, this is the best explanation I've seen for the code I'm talking about.
This code may be found at:
http://norvig.com/sudo.py
in the definition of the function eliminate. Here's the fragment:
elif len(values[s]) == 1:
## If there is only one value (d2) left in square, remove it from peers
d2, = values[s]
Now, in the assignment, values[s] *is* a string of length 1. So
this assignment appears to me entirely equivalent (in its ultimate
effect) to the more straightforward
d2 = values[s]
...but, since I'm a noob, I thought I'd ask :-)
Thanks!
kynn
--
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.
More information about the Python-list
mailing list