Re: my favorite line of py code so far

2013-11-10 Thread Peter Cacioppi
Chris said : "Absolutely! The unfortunate truth, though, is that idioms that resonate with you _and nobody else_ are just as big a problem as bugs, because they're unmaintainable. So hopefully what you're doing will make sense to other people too! " There is some truth in what you say ... but in

Re: my favorite line of py code so far

2013-11-10 Thread Chris Angelico
On Sun, Nov 10, 2013 at 7:57 PM, Peter Cacioppi wrote: > Chris said : > > "I think map is fine if you can use a named function, but if you can't > come up with a descriptive name for what you're doing, a comprehension > is probably better (as it'll have the code right there). Mapping _ > across ev

Re: my favorite line of py code so far

2013-11-10 Thread Peter Cacioppi
Sorry, typo, meant to say To be clear, I was never really intending to keep the _ = lambda c : lambda x : c(*x) map(_(P), zip([1,2,3], [6, 5, 4])) code snippets in my final work product. The purpose of this thread was too fish around for ideas on what to replace it with... -- https://m

Re: my favorite line of py code so far

2013-11-10 Thread Peter Cacioppi
Chris said : "I think map is fine if you can use a named function, but if you can't come up with a descriptive name for what you're doing, a comprehension is probably better (as it'll have the code right there). Mapping _ across everything tells you nothing about what it's actually doing" OK, thi

Re: my favorite line of py code so far

2013-11-09 Thread Peter Otten
Stefan Behnel wrote: > Peter Otten, 09.11.2013 12:49: >> There is no obvious meaning attached to _ -- so don't use it. > > Not quite true. Depending on the context, the obvious meanings of "_" in > Python are either > > 1) "ignore me", e.g. in > > _, b = some_tuple > > or > > 2) "this is

Re: my favorite line of py code so far

2013-11-09 Thread Chris Angelico
On Sat, Nov 9, 2013 at 11:41 PM, Stefan Behnel wrote: > 2) "this is a non-public thing", as in > > class Xyz: > _private = 1 Your three meanings all have the etymology of "ignore me", but I would distinguish this one from the others. An underscore used on its own has meaning; an under

Re: my favorite line of py code so far

2013-11-09 Thread Stefan Behnel
Peter Otten, 09.11.2013 12:49: > There is no obvious meaning attached to _ -- so don't use it. Not quite true. Depending on the context, the obvious meanings of "_" in Python are either 1) "ignore me", e.g. in _, b = some_tuple or 2) "this is a non-public thing", as in class Xyz:

Re: my favorite line of py code so far

2013-11-09 Thread Peter Otten
Peter Cacioppi wrote: > Peter Otten said: > > > ">>> _ = lambda c: lambda x: c(*x) list(map(_(P), zip([1,2,3], [6, 5, 4]))) > [Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)] > > ? While the obvious approach would be > [P(*args) for args in zip([1,2,3], [6, 5, 4])] > [Point(x=1, y

Re: my favorite line of py code so far

2013-11-09 Thread Paul Rubin
Peter Cacioppi writes: [P(*args) for args in zip([1,2,3], [6, 5, 4])] [P(x,y) for x,y in zip(...)] > Are you saying it's always preferable to avoid map? Not always. Depends on context, partly subjective. > I sometimes use map, sometimes comprehensions. I suspect other people > do the sam

Re: my favorite line of py code so far

2013-11-09 Thread Chris Angelico
On Sat, Nov 9, 2013 at 8:23 PM, Peter Cacioppi wrote: > I sometimes use map, sometimes comprehensions. I suspect other people do the > same, that's why the language supports map and comprehensions. I think map is fine if you can use a named function, but if you can't come up with a descriptive n

Re: my favorite line of py code so far

2013-11-09 Thread Peter Cacioppi
Peter Otten said: ">>> _ = lambda c: lambda x: c(*x) >>> list(map(_(P), zip([1,2,3], [6, 5, 4]))) [Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)] ? While the obvious approach would be >>> [P(*args) for args in zip([1,2,3], [6, 5, 4])] [Point(x=1, y=6), Point(x=2, y=5), Point(x=3, y=4)]

Re: my favorite line of py code so far

2013-11-08 Thread Peter Otten
Peter Cacioppi wrote: > my fav so far is this > > _ = lambda c : lambda x : c(*x) > > c can be any calleable and x any iterable, but I tend to use it with a > class, and then map _(class) over the result of a zip. > > It must be in the library somewhere, but I haven't found it. I'm never > sure

Re: my favorite line of py code so far

2013-11-08 Thread Peter Cacioppi
Chris said: "So... for any given class, it returns a tweaked version that unpacks an iterable of its arguments instead of taking separate args. " It works with any calleable (not just any class), but otherwise your summary is spot on. "Interesting, perhaps, but not something that'll be needed

Re: my favorite line of py code so far

2013-11-08 Thread Chris Angelico
On Sat, Nov 9, 2013 at 9:22 AM, Peter Cacioppi wrote: > my fav so far is this > > _ = lambda c : lambda x : c(*x) > > c can be any calleable and x any iterable, but I tend to use it with a class, > and then map _(class) over the result of a zip. > > It must be in the library somewhere, but I have

my favorite line of py code so far

2013-11-08 Thread Peter Cacioppi
my fav so far is this _ = lambda c : lambda x : c(*x) c can be any calleable and x any iterable, but I tend to use it with a class, and then map _(class) over the result of a zip. It must be in the library somewhere, but I haven't found it. I'm never sure what to call it, so I just reroll it i