
On Monday 20 October 2003 04:37 pm, Nick Coghlan wrote: ...
Well, I think we've established that at least two people on the planet love
Right, hopefully 3 with Greg (though it's not unheard of for posters to this list to change their minds about their own proposals. So I told myself I should stay out of the thread to let others voice their opinion, BUT...:
for x in sorted_copy of reversed_copy of my_list:
Ooops -- sorting a reversed copy of my_list is just like sorting my_list... I think for x in sorted_copy(reverse=True) of my_list: ... (again borrowing brand-new keyword syntax from lists' sort method) is likely to work better...:-)
Hmm, just had a strange thought:
y = copy of x
How would that be for executable pseudocode? It's entirely possible to do
Awesomely pseudocoder (what a comparative...!-) wrt the current "y = copy.copy(x)". You WOULD need to "from copy import copy" first, presumably, but still...
all the iterator related things without having this last example work. But what if it did?
Then the special method would have to be passed the right-hand operand verbatim, NOT an iterator on it, for the "NAME 'of' test" case; otherwise, this would be a terrible "attractive nuisance" in such cases as x = copy of my_dict (if the hypothetical special method was passed iter(my_dict), it would only get the KEYS -- shudder -- so x would presumably end up as a list -- a trap for the unwary, and one I wouldn't want to have to explain to newbies!-). However, if I had to choose, I would forego this VERY attractive syntax sugar, and go for Greg's original suggestion -- 'of' for iterator comprehensions only. Syntax sugar is all very well (at least in this case), but if it _only_ amounts to a much neater-looking way of doing what is already quite possible, it's a "more-than-one-way-to-do-itis". [Just to make sure I argue both sides: introducing "if key in mydict:" as a better way to express "if mydict.has_key(key):" was a HUGE win, and so was letting "if needle in haystack:" be used as a better way to express "haystack.find(needle) >= 0" for substring checks -- so, 'mere' syntax sugar DOES sometimes make an important difference...] Alex