Re: a &= b

2019-10-04 Thread David
On Fri, 4 Oct 2019 at 19:02, Hongyi Zhao wrote: > > Could you please give me some more hints on: > > a &= b $ python3 Python 3.5.3 (default, Sep 27 2018, 17:25:39) [GCC 6.3.0 20170516] on linux Type "help", "copyright", "credits" or "license" for more information. >>> >>> a = 15 >>> b = 3 >>> c =

Re: a &= b

2019-10-04 Thread Joel Goldstick
On Fri, Oct 4, 2019 at 5:01 AM Hongyi Zhao wrote: > > Hi, > > Could you please give me some more hints on: > > a &= b > > It's very difficult for me to understand. > -- > https://mail.python.org/mailman/listinfo/python-list & is bitwise And. a &= b is equivalent to a = a & b -- Joel Goldstick

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka
03.09.19 11:02, Chris Angelico пише: On Tue, Sep 3, 2019 at 5:53 PM Serhiy Storchaka wrote: 02.09.19 12:24, Chris Angelico пише: But the curious difference happens in 3.7. I don't know what changed to cause this, but from there on, the list gets built and then unpacked. This was a side effe

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Chris Angelico
On Tue, Sep 3, 2019 at 5:53 PM Serhiy Storchaka wrote: > > 02.09.19 12:24, Chris Angelico пише: > > But the curious difference happens in 3.7. I don't know what changed > > to cause this, but from there on, the list gets built and then > > unpacked. > > This was a side effect of moving the optimiz

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-03 Thread Serhiy Storchaka
02.09.19 12:24, Chris Angelico пише: But the curious difference happens in 3.7. I don't know what changed to cause this, but from there on, the list gets built and then unpacked. This was a side effect of moving the optimization for `x in [a, b]` from the peepholer to the AST optimizer. -- h

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-02 Thread Eko palypse
Am Montag, 2. September 2019 00:49:05 UTC+2 schrieb Hongyi Zhao: > Hi, > > What's differences: > > a,b = 2,3 and [a,b] = [2,3] > > Regards In this example the result is the same but the second one builds, internally, an additional list, therefore isn't as sufficient as the first one. -- https:

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-02 Thread Chris Angelico
On Mon, Sep 2, 2019 at 6:31 PM Alan Bawden wrote: > > Dang! There is exactly the instruction sequence I just argued could be > optimized away still sitting right there. So maybe my belief that this is > being done by peephole optimization is in fact incorrect? So I went and > tried again: > > b

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-02 Thread Alan Bawden
Chris Angelico writes: > On Mon, Sep 2, 2019 at 12:36 PM Alan Bawden wrote: ... > > > > a,b = 2,3 and [a,b] = [2,3] ... > > It looks to me like they generate identical code. The first one calls the > > construction of a tuple, where the second one calls for the construction of > > a list. It w

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-01 Thread Chris Angelico
On Mon, Sep 2, 2019 at 12:36 PM Alan Bawden wrote: > > Eko palypse writes: > > > Am Montag, 2. September 2019 00:49:05 UTC+2 schrieb Hongyi Zhao: > > > Hi, > > > > > > What's differences: > > > > > > a,b = 2,3 and [a,b] = [2,3] > > > > > > Regards > > > > In this example the result is the same bu

Re: a,b = 2,3 and [a,b] = [2,3]

2019-09-01 Thread Alan Bawden
Eko palypse writes: > Am Montag, 2. September 2019 00:49:05 UTC+2 schrieb Hongyi Zhao: > > Hi, > > > > What's differences: > > > > a,b = 2,3 and [a,b] = [2,3] > > > > Regards > > In this example the result is the same but the second one > builds, internally, an additional list, therefore isn'

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Chris Angelico
On Fri, Aug 26, 2016 at 8:20 PM, mlz wrote: > I believe there are languages that preserve exact accuracy in this way for > rational fractions. I don't know if Python is one of them. It is, but only if you explicitly request it (due to the performance impact). Just import it: #!/usr/bin/python2

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Jussi Piitulainen
mlz writes: > It's true that a*(b/c) yields fractions which would probably accrue > accuracy errors depending on how those values are implemented. For > example, it is possible to represent 1/3 internally as two numbers, > numerator and denominator, thus avoiding the repeating decimal (or > binima

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlz
It's true that a*(b/c) yields fractions which would probably accrue accuracy errors depending on how those values are implemented. For example, it is possible to represent 1/3 internally as two numbers, numerator and denominator, thus avoiding the repeating decimal (or binimal, or whatever it's

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlz
Partly it's the layout, but mathematically speaking the two should be equal. (a*b)/c should equal a*(b/c) The fact that they're not is surprising, because python 2 so seamlessly supports big integers in a mathematically correct way. I consider such surprising behavior to be abstraction leak, wh

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlz
Aha. That's interesting. On Friday, August 26, 2016 at 2:11:32 AM UTC-7, Peter Otten wrote: > mlz wrote: > > > Yes, I just worked that out. It's the integer math that's the problem. > > > > I guess this has been fixed in python 3, but unfortunately it seems that > > most people are still using

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread BartC
On 26/08/2016 08:14, mlzarathus...@gmail.com wrote: However, precedence wasn't the problem in this case, it was the type conversion. I think it was. I was puzzled as well. But apparently if you have: x * = expr That's like: x = x * (expr)# note the parentheses which may not al

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Peter Otten
mlzarathus...@gmail.com wrote: > Yes, I just worked that out. It's the integer math that's the problem. > > I guess this has been fixed in python 3, but unfortunately it seems that > most people are still using python 2. Note that you can get Python 3's default behaviour in Python 2 with from _

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Christian Gollwitzer
Am 26.08.16 um 09:53 schrieb Erik: On 26/08/16 08:44, mlzarathus...@gmail.com wrote: Here's the key: $ python2 Python 2.7.10 ... 1/2 0 $ python Python 3.5.1 ... 1/2 0.5 1//2 0 I read about this awhile ago, but it's not until it bites you that you remember fully. How is this rela

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Erik
On 26/08/16 08:14, mlzarathus...@gmail.com wrote: I was being facetious, but behind it is a serious point. Neither the APL nor the J languages use precedence even though their inventor, Ken Iverson, was a mathematician. That was to support functional programming dating back to the 1970's. P

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Erik
On 26/08/16 08:44, mlzarathus...@gmail.com wrote: Here's the key: $ python2 Python 2.7.10 ... 1/2 0 $ python Python 3.5.1 ... 1/2 0.5 1//2 0 I read about this awhile ago, but it's not until it bites you that you remember fully. How is this related to your question? The example e

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlzarathustra
Here's the key: $ python2 Python 2.7.10 ... >>> 1/2 0 >>> $ python Python 3.5.1 ... >>> 1/2 0.5 >>> 1//2 0 >>> I read about this awhile ago, but it's not until it bites you that you remember fully. -- https://mail.python.org/mailman/listinfo/python-list

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread Jussi Piitulainen
mlzarathus...@gmail.com writes: > Yes, I just worked that out. It's the integer math that's the problem. > > I guess this has been fixed in python 3 [- -] Note that division in Python 3 produces approximate results (floating point numbers). This may or may not be what you want in this exercise. I

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlzarathustra
I was being facetious, but behind it is a serious point. Neither the APL nor the J languages use precedence even though their inventor, Ken Iverson, was a mathematician. That was to support functional programming dating back to the 1970's. However, precedence wasn't the problem in this case, i

Re: a *= b not equivalent to a = a*b

2016-08-26 Thread mlzarathustra
Yes, I just worked that out. It's the integer math that's the problem. I guess this has been fixed in python 3, but unfortunately it seems that most people are still using python 2. Thanks for all the help! -- https://mail.python.org/mailman/listinfo/python-list

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread Peter Otten
mlz wrote: > I've been playing with the binomial function, and found that in the below > code, rs *= x does not behave the same way as rs = rs * x. When I set FAIL > to True, I get a different result. Both results are below. > > I had read that the two were equivalent. What am I missing? > > th

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread Chris Angelico
On Fri, Aug 26, 2016 at 4:40 PM, wrote: > Precedence, d'oh! > > rs *= (n-(i-1))/i > is equivalent to: > rs = rs * ((n-(i-1))/i) > > not > rs = rs * (n-(i-1))/i > > which is the same as > rs = ( rs * (n-(i-1)) ) /i > > > Ken Iverson was right. Precedence is a bad i

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread mlzarathustra
Precedence, d'oh! rs *= (n-(i-1))/i is equivalent to: rs = rs * ((n-(i-1))/i) not rs = rs * (n-(i-1))/i which is the same as rs = ( rs * (n-(i-1)) ) /i Ken Iverson was right. Precedence is a bad idea. -- https://mail.python.org/mailman/listinfo/python

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread INADA Naoki
if FAIL: rs *= (n-(i-1))/i # these should be the same, This is equal to rs = rs * ((n-(i-1))/i) else: rs = rs * (n-(i-1))/i # but apparently are not This is equal to rs = (rs * (n-(i-1)))/i On Fri, Aug 26, 2016 at 3:20 PM, mlz wrote: > I've been playing with the binomial f

Re: a *= b not equivalent to a = a*b

2016-08-25 Thread Jussi Piitulainen
mlz writes: > I've been playing with the binomial function, and found that in the > below code, rs *= x does not behave the same way as rs = rs * x. When > I set FAIL to True, I get a different result. Both results are below. > > I had read that the two were equivalent. What am I missing? You do

Re: [a,b,c,d] = 1,2,3,4

2015-08-26 Thread Terry Reedy
On 8/26/2015 8:21 AM, Tim Chase wrote: a, b, c = (x for x in range(3)) # a generator for instance Since range() *is* a generator, why not just use In Python 3, range is a sequence class with a separate iterator class >>> r = range(3) >>> r range(0, 3) >>> iter(r) Like all sequences, a ran

Re: [a,b,c,d] = 1,2,3,4

2015-08-26 Thread Jean-Michel Pichavant
- Original Message - > From: "Chris Angelico" > Cc: python-list@python.org > Sent: Wednesday, 26 August, 2015 3:04:05 PM > Subject: Re: [a,b,c,d] = 1,2,3,4 > > On Wed, Aug 26, 2015 at 12:59 AM, Jean-Michel Pichavant > wrote: > > To add to Joel

Re: [a,b,c,d] = 1,2,3,4

2015-08-26 Thread Chris Angelico
On Wed, Aug 26, 2015 at 12:59 AM, Jean-Michel Pichavant wrote: > To add to Joel's answer, the right side can be *any* sequence, and is not > restricted to lists or tuples. > > a, b, c = (x for x in range(3)) # a generator for instance FWIW, a generator is not a sequence; this works because the r

Re: [a,b,c,d] = 1,2,3,4

2015-08-26 Thread Tim Chase
On 2015-08-25 16:59, Jean-Michel Pichavant wrote: > - Original Message - > > From: "Joel Goldstick" > > its called list unpacking or packing (?) > > > > the right side is considered a tuple because of the commas > > >>> a = 1,2,3 > > >>> a > > (1, 2, 3) > > >>> a[1] > > 2 > > To add to J

Re: [a,b,c,d] = 1,2,3,4

2015-08-26 Thread Jean-Michel Pichavant
- Original Message - > From: "Joel Goldstick" > its called list unpacking or packing (?) > > the right side is considered a tuple because of the commas > >>> a = 1,2,3 > >>> a > (1, 2, 3) > >>> a[1] > 2 To add to Joel's answer, the right side can be *any* sequence, and is not restricted

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
Ian Kelly writes: > On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro wrote: >> On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote: >>> >>> When I try it today, round brackets also work, both in 2.6.6 and >>> 3.4.0 - no idea what version it was where they failed or if I'm >>> imagining the who

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
Skip Montanaro writes: > On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen wrote: > >> When I try it today, round brackets also work, both in 2.6.6 and >> 3.4.0 - no idea what version it was where they failed or if I'm >> imagining the whole thing. > > You are imagining the whole thing. Either

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Ian Kelly
On Tue, Aug 25, 2015 at 9:32 AM, Skip Montanaro wrote: > > On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen > wrote: >> >> When I try it today, round brackets >> also work, both in 2.6.6 and 3.4.0 - no idea what version it was where >> they failed or if I'm imagining the whole thing. > > > You

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Skip Montanaro
On Tue, Aug 25, 2015 at 10:24 AM, Jussi Piitulainen < harvested.address@is.invalid> wrote: > When I try it today, round brackets > also work, both in 2.6.6 and 3.4.0 - no idea what version it was where > they failed or if I'm imagining the whole thing. > You are imagining the whole thing. Either

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jussi Piitulainen
"ast" writes: [a,b,c,d] = 1,2,3,4 a > 1 b > 2 c > 3 d > 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? I remember being unhappy when a similar assignment with round brackets turned out to be invalid syntax. Then I learned (in th

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast
"Joel Goldstick" a écrit dans le message de news:mailman.27.1440515128.11709.python-l...@python.org... On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall wrote: On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: The original example is one I haven't seen in the wild. I found it using matplotl

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast
"ast" a écrit dans le message de news:55dc853c$0$3083$426a7...@news.free.fr... "Joel Goldstick" a écrit dans le message de news:mailman.23.1440513059.11709.python-l...@python.org... On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: [a,b,c,d] = 1,2,3,4 a 1 b 2 c 3 d 4 I have nev

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread ast
"Joel Goldstick" a écrit dans le message de news:mailman.23.1440513059.11709.python-l...@python.org... On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: [a,b,c,d] = 1,2,3,4 a 1 b 2 c 3 d 4 I have never seen this syntax before. Is it documented. Is there a name for that ? thx -- ht

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Joel Goldstick
On Tue, Aug 25, 2015 at 10:32 AM, Cody Piersall wrote: > > > On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: > > [a,b,c,d] = 1,2,3,4 > a >> >> 1 > > b >> >> 2 > > c >> >> 3 > > d >> >> 4 >> >> I have never seen this syntax before. Is it documented. >> Is there a na

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Jean-Michel Pichavant
- Original Message - > From: "ast" > To: python-list@python.org > Sent: Tuesday, 25 August, 2015 4:16:17 PM > Subject: [a,b,c,d] = 1,2,3,4 > > >>> [a,b,c,d] = 1,2,3,4 > >>> a > 1 > >>> b > 2 > >>> c > 3 > >>> d > 4 > > I have never seen this syntax before. Is it documented. > Is there a

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Cody Piersall
On Tue, Aug 25, 2015 at 9:16 AM, ast wrote: > [a,b,c,d] = 1,2,3,4 a >>> 1 > >> b >>> 2 > >> c >>> 3 > >> d >>> 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? > > thx > -- > https://mail.python.org/mailman/listinfo/python-list >

Re: [a,b,c,d] = 1,2,3,4

2015-08-25 Thread Joel Goldstick
On Tue, Aug 25, 2015 at 10:16 AM, ast wrote: [a,b,c,d] = 1,2,3,4 a > > 1 b > > 2 c > > 3 d > > 4 > > I have never seen this syntax before. Is it documented. > Is there a name for that ? > > thx > -- > https://mail.python.org/mailman/listinfo/python-list its

Re: a +b ?

2010-06-17 Thread David Robinow
On Wed, Jun 16, 2010 at 11:34 PM, Aahz wrote: > In article , > James Mills   wrote: ... >>What in particular do you _not_ enjoy about using map/reduce (and >>possibly other functional features of the Python programing language) ? > > map() never felt particularly Pythonic, especially the way it wo

Re: a +b ?

2010-06-16 Thread Mark Lawrence
On 17/06/2010 06:12, James Mills wrote: On Thu, Jun 17, 2010 at 2:53 PM, Stephen Hansen wrote: My entire response was largely tongue-in-cheek :) I know :) Don't you wish there was a "Close Thread" button :) For the more disgraceful/disgusting threads around here in recent days I wish th

Re: a +b ?

2010-06-16 Thread James Mills
On Thu, Jun 17, 2010 at 2:53 PM, Stephen Hansen wrote: > My entire response was largely tongue-in-cheek :) I know :) Don't you wish there was a "Close Thread" button :) -- -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-16 Thread James Mills
On Thu, Jun 17, 2010 at 2:43 PM, James Mills wrote: > /me withdraws from this discussion :) Of course - thank you for that enlightening description of "Pythonic" :) Hopefully it helps others to understand! :) -- -- -- "Problems are solved by method" -- http://mail.python.org/mailman/listinfo/

Re: a +b ?

2010-06-16 Thread Stephen Hansen
On 6/16/10 9:43 PM, James Mills wrote: > On Thu, Jun 17, 2010 at 2:23 PM, Stephen Hansen > wrote: >> It could certainly do with a little less 'taking oneself too seriously' :) > > You do realize my question was completely rhetorical :) > > --James > > /me withdraws from this discussion :) My e

Re: a +b ?

2010-06-16 Thread James Mills
On Thu, Jun 17, 2010 at 2:23 PM, Stephen Hansen wrote: > It could certainly do with a little less 'taking oneself too seriously' :) You do realize my question was completely rhetorical :) --James /me withdraws from this discussion :) -- -- -- "Problems are solved by method" -- http://mail.py

Re: a +b ?

2010-06-16 Thread Stephen Hansen
On 6/16/10 9:03 PM, James Mills wrote: > Further: What is "Pythonic" ? This is probably more of a style and > personal taste that might vary from one programmer to another. > I don't recall anywhere in the Python documentation or a Python > document that says map/reduce is or isn't "pythonic" (what

Re: a +b ?

2010-06-16 Thread James Mills
On Thu, Jun 17, 2010 at 1:34 PM, Aahz wrote: >>"Loathe" is a particularly STRONG world. Are you sure you meant that ? > > Yes, I did mean to use it -- perhaps it is not entirely an accurate > description of my emotional state, but I enjoy the shock effect in this > circumstance. > >>What in partic

Re: a +b ?

2010-06-16 Thread Aahz
In article , James Mills wrote: >On Thu, Jun 17, 2010 at 12:37 PM, Aahz wrote: >> >> And I am not particularly fond of map() and cordially loathe reduce(). >> Speaking as someone with more than twenty years of programming before >> encountering Python more than a decade ago. > >"Loathe" is a par

Re: a +b ?

2010-06-16 Thread James Mills
On Thu, Jun 17, 2010 at 12:37 PM, Aahz wrote: > And I am not particularly fond of map() and cordially loathe reduce(). > Speaking as someone with more than twenty years of programming before > encountering Python more than a decade ago. "Loathe" is a particularly STRONG world. Are you sure you me

Re: a +b ?

2010-06-16 Thread Aahz
In article , alex23 wrote: > >I've never used map/reduce outside of Python, this is where I first >encountered it. And I _have_ worked in organisations alongside new >Python coders. That it's easy enough to express both map & reduce in >Python code helped a lot with explaining them. And I am not

Re: a +b ?

2010-06-15 Thread Ben Finney
alex23 writes: > Ben Finney wrote: > > Thanks for clarifying that you were not expressing the attitude I > > inferred. > > Ah, crap, I didn't see this until now. I _did_ take the wrong meaning > from it and unfortunately replied accordingly :| So please take this > as a sincere apology (laced wi

Re: a +b ?

2010-06-15 Thread alex23
Ben Finney wrote: > It should go without saying, but unfortunately the tenor of this forum > has been worsened (temporarily, I hope) by certain interminable threads > of late. So, to be clear: > > Thanks for clarifying that you were not expressing the attitude I > inferred. Ah, crap, I didn't see

Re: a +b ?

2010-06-15 Thread alex23
Ben Finney wrote: > No, it wasn't clear at all. That's why I asked, rather than making > assumptions. > > Thanks for clarifying. No problem. Thank you for another pleasant exchange. -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-14 Thread Ben Finney
Ben Finney writes: > No, it wasn't clear at all. That's why I asked, rather than making > assumptions. > > Thanks for clarifying. It should go without saying, but unfortunately the tenor of this forum has been worsened (temporarily, I hope) by certain interminable threads of late. So, to be clea

Re: a +b ?

2010-06-14 Thread Steven D'Aprano
On Mon, 14 Jun 2010 23:05:56 -0700, alex23 wrote: > And I'm saying that I hope that most people who are professional > developers are capable of learning such advanced functionality, which > they will never do if there are no effective examples for them from > which to learn. I'm not sure why Pyth

Re: a +b ?

2010-06-14 Thread Ben Finney
alex23 writes: > Ben Finney wrote: > > alex23 writes: > > > (Although I have to say, I have little sympathy for Steven's > > > hypothetical "new programmer who isn't familiar with map and > > > reduce". > > > > With ‘reduce’ gone in Python 3 [0], I can only interpret that as “I > > have little

Re: a +b ?

2010-06-14 Thread alex23
Steven D'Aprano wrote: > Perhaps you need to spend some more time helping beginners then, and less > time hanging around Lisp gurus *wink* I've never used map/reduce outside of Python, this is where I first encountered it. And I _have_ worked in organisations alongside new Python coders. That it'

Re: a +b ?

2010-06-14 Thread alex23
Ben Finney wrote: > alex23 writes: > > (Although I have to say, I have little sympathy for Steven's > > hypothetical "new programmer who isn't familiar with map and reduce". > > With ‘reduce’ gone in Python 3 [0], I can only interpret that as “I have > little sympathy for programmers who start wi

Re: a +b ?

2010-06-14 Thread Thomas Jollans
On 06/14/2010 09:15 AM, Steven D'Aprano wrote: > On Mon, 14 Jun 2010 12:24:59 +1000, Ben Finney wrote: > >> With ‘reduce’ gone in Python 3 [0] > ... >> [0] http://docs.python.org/py3k/library/functions.html> > > > It's not gone, it's just resting. It's pinin' for the fjords. (sorry ^^) > >

Re: a +b ?

2010-06-14 Thread Ian
On 14/06/2010 02:35, alex23 wrote: Python isn't PHP, its built-ins are nowhere near as exhaustive, something like 80ish vs 2000+ functions? Not exactly a huge lookup burden. The problem is not learning Python, its learning about the standard libraries that Python gives you access to! .NET

Re: a +b ?

2010-06-14 Thread Mark Dickinson
On Jun 13, 5:46 pm, exar...@twistedmatrix.com wrote: > On 04:25 pm, wuwe...@gmail.com wrote: > > > > >Steven D'Aprano wrote: > >>No, I think your code is very simple. You can save a few lines by > >>writing > >>it like this: > > >>s = input('enter two numbers: ') > >>t = s.split() > >>print(int(t[

Re: a +b ?

2010-06-14 Thread cristeto1981
alex23 wrote: > > exar...@twistedmatrix.com wrote: >> Fore! >> >>     print(sum(map(int, input('enter two numbers: ').split( > > Well, I _was_ trying to stick to Steven's more simple map-less form :) > > (Although I have to say, I have little sympathy for Steven's > hypothetical "new prog

Re: a +b ?

2010-06-14 Thread Mark Leander
(pytyhon 2.x code): print input('Enter expression: ') Example uses: Enter expression: 3+4 7 Enter expression: 1+2+3+4+5 15 Enter expression: 7*18 126 Enter expression: 2**19-1 524287 -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-14 Thread Steven D'Aprano
On Mon, 14 Jun 2010 12:24:59 +1000, Ben Finney wrote: > With ‘reduce’ gone in Python 3 [0] ... > [0] http://docs.python.org/py3k/library/functions.html> It's not gone, it's just resting. http://docs.python.org/py3k/library/functools.html#functools.reduce -- Steven -- http://mail.python.org/

Re: a +b ?

2010-06-13 Thread Steven D'Aprano
On Sun, 13 Jun 2010 18:35:52 -0700, alex23 wrote: > I have little sympathy for Steven's > hypothetical "new programmer who isn't familiar with map and reduce". Perhaps you need to spend some more time helping beginners then, and less time hanging around Lisp gurus *wink* > Python isn't PHP, its

Re: a +b ?

2010-06-13 Thread Ben Finney
alex23 writes: > (Although I have to say, I have little sympathy for Steven's > hypothetical "new programmer who isn't familiar with map and reduce". With ‘reduce’ gone in Python 3 [0], I can only interpret that as “I have little sympathy for programmers who start with Python 3”. Is that in line

Re: a +b ?

2010-06-13 Thread geremy condra
On Sun, Jun 13, 2010 at 9:46 AM, wrote: > On 04:25 pm, wuwe...@gmail.com wrote: >> >> Steven D'Aprano wrote: >>> >>> No, I think your code is very simple. You can save a few lines by writing >>> it like this: >>> >>> s = input('enter two numbers: ') >>> t = s.split() >>> print(int(t[0]) + int(t[

Re: a +b ?

2010-06-13 Thread alex23
exar...@twistedmatrix.com wrote: > Fore! > >     print(sum(map(int, input('enter two numbers: ').split( Well, I _was_ trying to stick to Steven's more simple map-less form :) (Although I have to say, I have little sympathy for Steven's hypothetical "new programmer who isn't familiar with map

Re: a +b ?

2010-06-13 Thread Martin
On Jun 13, 5:46 pm, exar...@twistedmatrix.com wrote: > On 04:25 pm, wuwe...@gmail.com wrote: > > > > > > >Steven D'Aprano wrote: > >>No, I think your code is very simple. You can save a few lines by > >>writing > >>it like this: > > >>s = input('enter two numbers: ') > >>t = s.split() > >>print(in

Re: a +b ?

2010-06-13 Thread exarkun
On 04:25 pm, wuwe...@gmail.com wrote: Steven D'Aprano wrote: No, I think your code is very simple. You can save a few lines by writing it like this: s = input('enter two numbers: ') t = s.split() print(int(t[0]) + int(t[1])) # no need for temporary variables a and b Not that we're playing

Re: a +b ?

2010-06-13 Thread alex23
Steven D'Aprano wrote: > No, I think your code is very simple. You can save a few lines by writing > it like this: > > s = input('enter two numbers: ') > t = s.split() > print(int(t[0]) + int(t[1])) # no need for temporary variables a and b Not that we're playing a round of code golf here, but t

Re: a +b ?

2010-06-11 Thread Steven D'Aprano
On Fri, 11 Jun 2010 22:11:26 +0800, yanhua wrote: > hi,all! > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,can anybody tell to slove i

Re: a +b ?

2010-06-11 Thread Alain Ketterlin
yanhua writes: > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() input() is probably not what you think it is. Check raw_input instead. > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,

Re: a +b ?

2010-06-11 Thread Xavier Ho
2010/6/12 yanhua > hi,all! > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,can anybody tell to slove it with less code. > -- > The reas

Re: a +b ?

2010-06-11 Thread superpollo
Simon Brunning ha scritto: 2010/6/11 yanhua : hi,all! it's a simple question: input two integers A and B in a line,output A+B? print sum(int(i) for i in raw_input("Please enter some integers: ").split()) LOL -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-11 Thread Simon Brunning
2010/6/11 yanhua : > hi,all! > it's a simple question: > input two integers A and B in a line,output A+B? print sum(int(i) for i in raw_input("Please enter some integers: ").split()) -- Cheers, Simon B. -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-11 Thread Alex Hall
On 6/11/10, yanhua wrote: > hi,all! > it's a simple question: > input two integers A and B in a line,output A+B? > > this is my program: > s = input() > t = s.split() > a = int(t[0]) > b = int(t[1]) > print(a+b) > > but i think it's too complex,can anybody tell to slove it with less code. Just a t

Re: a +b ?

2010-06-11 Thread Martin P. Hellwig
On 06/11/10 15:19, superpollo wrote: yanhua ha scritto: hi,all?? s = input() this does not work Well it does if it is python 3 and not 2 as you are using :-) -- mph -- http://mail.python.org/mailman/listinfo/python-list

Re: a +b ?

2010-06-11 Thread superpollo
yanhua ha scritto: hi,all?? it's a simple question: input two integers A and B in a line,output A+B? this is my program: s = input() this does not work t = s.split() a = int(t[0]) b = int(t[1]) print(a+b) but i think it's too complex,can anybody tell to slove it with less code. >>> import

Re: (a==b) ? 'Yes' : 'No'

2010-04-19 Thread Dotan Cohen
On 30 March 2010 18:40, gentlestone wrote: > Hi, how can I write the popular C/JAVA syntax in Python? > > Java example: >    return (a==b) ? 'Yes' : 'No' > > My first idea is: >    return ('No','Yes')[bool(a==b)] > > Is there a more elegant/common python expression for this? > I'm a little late t

Re: (a==b) ? 'Yes' : 'No'

2010-04-11 Thread Steven D'Aprano
On Sun, 11 Apr 2010 21:35:49 -0700, Aahz wrote: > In article , Steve > Holden wrote: >> >>It exists because people nagged Guido mercilessly until, against his >>better judgment, he capitulated. > > No, the ternary exists because he became convinced that it was the > lesser evil compared with le

Re: (a==b) ? 'Yes' : 'No'

2010-04-11 Thread Aahz
In article , Steve Holden wrote: > >It exists because people nagged Guido mercilessly until, against his >better judgment, he capitulated. No, the ternary exists because he became convinced that it was the lesser evil compared with letting the abomination of A and B or C remain the "Pythonic"

Re: (a==b) ? 'Yes' : 'No'

2010-04-07 Thread Emile van Sebille
On 4/6/2010 9:20 PM Steven D'Aprano said... On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote: Most old hands would (IMHO) write the if statements out in full, though some might remember that Python comes 'batteries included': from bisect import bisect WEIGHTS = [100, 250, 500, 1000]

Re: (a==b) ? 'Yes' : 'No'

2010-04-07 Thread Duncan Booth
Steven D'Aprano wrote: > On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote: > >> Albert van der Horst wrote: >> >>> Old hands would have ... >>> stamp =( weight>=1000 and 120 or >>> weight>=500 and 100 or >>> weight>=250 and 80 or >>> weigh

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Steven D'Aprano
On Tue, 06 Apr 2010 16:54:18 +, Duncan Booth wrote: > Albert van der Horst wrote: > >> Old hands would have ... >> stamp =( weight>=1000 and 120 or >> weight>=500 and 100 or >> weight>=250 and 80 or >> weight>=100 and 60 or >>

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Duncan Booth
Albert van der Horst wrote: > Old hands would have ... > stamp =( weight>=1000 and 120 or > weight>=500 and 100 or > weight>=250 and 80 or > weight>=100 and 60 or >44 ) > > (Kind of a brain twister, I think, inf

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Lie Ryan
On 04/07/10 00:16, Albert van der Horst wrote: > In article , > Peter Otten <__pete...@web.de> wrote: >> Pierre Quentel wrote: >> >>> I'm surprised nobody proposed a solution with itertools ;-) >> >> next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") > > I could learn something here, if y

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Albert van der Horst
In article , Steve Holden wrote: >kj wrote: >> In Steve Holden >> writes: >> >>> John Nagle wrote: Chris Rebert wrote: > On Tue, Mar 30, 2010 at 8:40 AM, gentlestone > wrote: >> Hi, how can I write the popular C/JAVA syntax in Python? >> >> Java example: >>ret

Re: (a==b) ? 'Yes' : 'No'

2010-04-06 Thread Albert van der Horst
In article , Peter Otten <__pete...@web.de> wrote: >Pierre Quentel wrote: > >> I'm surprised nobody proposed a solution with itertools ;-) > >next(itertools.takewhile(lambda _: a == b, ["yes"]), "no") I could learn something here, if you explain it? > >You spoke to soon :) > >Peter Groetjes Alb

Re: (a==b) ? 'Yes' : 'No'

2010-04-04 Thread Steven D'Aprano
On Mon, 05 Apr 2010 12:08:31 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: > >> Not according to the PEP. No fewer than 16 alternatives were put to a >> vote, and with no clear winner (but many obvious losers) Guido made the >> final decision. > > As I remember, the decision made on the b

Re: (a==b) ? 'Yes' : 'No'

2010-04-04 Thread Gregory Ewing
Steven D'Aprano wrote: Not according to the PEP. No fewer than 16 alternatives were put to a vote, and with no clear winner (but many obvious losers) Guido made the final decision. As I remember, the decision made on the basis of the vote was *not* to add a conditional expression at all, beca

Re: (a==b) ? 'Yes' : 'No'

2010-04-03 Thread Steven D'Aprano
On Sun, 04 Apr 2010 12:26:05 +1200, Lawrence D'Oliveiro wrote: > In message , Steve > Holden wrote: > >> Lawrence D'Oliveiro wrote: >> >>> By the way, you don’t need the parentheses. >> >> But at the same time, if you don't *absolutely know* you don't need the >> parentheses ... > > But you can

Re: (a==b) ? 'Yes' : 'No'

2010-04-03 Thread Lawrence D'Oliveiro
In message , Steve Holden wrote: > Lawrence D'Oliveiro wrote: > >> By the way, you don’t need the parentheses. > > But at the same time, if you don't *absolutely know* you don't need the > parentheses ... But you can “abolutely know”—it’s all spelled out here

  1   2   >