Re: [Tutor] apply() vs. the extended call syntax

2013-08-02 Thread Dave Angel
Tim Johnson wrote: > * Tim Johnson [130802 15:41]: > <...> Is there a cleaner way to do this? using apply() >> looks so much simpler, but I understand it is not even available in >> py 3 > def apl(funcall): funcall[0](*funcall[1]) > k = "key2" > >>> apl(func_D[k]) > I don't have an a

Re: [Tutor] implied tuple in a list comprehension

2013-08-02 Thread ALAN GAULD
>> t = (6,)  # t=6,  works but is much harder to see. > > That could lead to awful bugs, since it really is hard to see, and > hitting the comma is a mistake I often make. I think I may stick with > always using parentheses for tuples. Some conveniences aren't that > convenient. And this from

Re: [Tutor] implied tuple in a list comprehension

2013-08-02 Thread Alan Gauld
On 02/08/13 19:13, Jim Mooney wrote: comma, then word in S, which made no sense, instead of unpacking - word for (idx, word) in S. Done in again by the implied tuple ;') Just to pick up a point that might be confusing you. A tuple does not need parentheses. >>> tup = 5,4 >>> tup (5, 4) >>> t

Re: [Tutor] implied tuple in a list comprehension

2013-08-02 Thread Hugo Arts
On Fri, Aug 2, 2013 at 10:02 AM, Jim Mooney wrote: > On 2 August 2013 00:46, Alan Gauld wrote: > > On 02/08/13 08:32, Jim Mooney wrote: > > > How should Python interpret this? > > > > As > > > > x = [idx, (word for idx, word in S)] > > > > Or > > > > > > x = [(idx, word) for idx, word in S] > > >

Re: [Tutor] implied tuple in a list comprehension

2013-08-02 Thread Steven D'Aprano
On 02/08/13 18:02, Jim Mooney wrote: I see what you mean, but I figured it can't be ambiguous if one interpretation makes no sense, and I can't see what x = [idx, (word for idx, word in S)] could possibly mean. Am I assuming too much foresight on the part of the parser or does that actually me

Re: [Tutor] implied tuple in a list comprehension

2013-08-02 Thread Alan Gauld
On 02/08/13 08:32, Jim Mooney wrote: x = [idx, word for idx, word in S] #syntax error # Why can I imply a tuple after the for, but not before? How should Python interpret this? As x = [idx, (word for idx, word in S)] Or x = [(idx, word) for idx, word in S] It's ambiguous. -- Alan G Autho