Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
On 12/07/2017 10:28 AM, Ethan Furman wrote: The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. Thankfully, Paul answered that question with a good explanation*. Thanks, everyone, for the discussion. -- ~Ethan~

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ben Finney
Nathan Ernst writes: > There is a built-in identity function in Python. The function is called > 'id'. It should be clear from the rest of the thread. But, to be explicit: That's not what is meant by “identity function”, and the Python ‘id’ function is not an identity function. The Python ‘id’

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ben Finney
Ethan Furman writes: > My contention is that an identity function is a do-nothing function > that simply returns what it was given: > > --> identity(1) > 1 > > --> identity('spam') > 'spam' These seem good to me. One argument given, the same result returned. > --> identity('spam', 'eggs', 7) >

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Paul Moore
On 7 December 2017 at 20:35, Chris Angelico wrote: > Because it's impossible to return multiple values. IMO the "identity > function" is defined only in terms of one single argument, so all of > this is meaningless. Indeed, this is the key point. The Python language only allows returning one valu

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Lele Gaifax
Chris Angelico writes: > On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: >> Chris Angelico writes: >> >>> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__pete...@web.de> wrote: Hm, what does -- and what should -- identity(('spam', 'eggs', 7)) produce? >>> >>> The

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Chris Angelico
On Fri, Dec 8, 2017 at 8:30 AM, Lele Gaifax wrote: > Chris Angelico writes: > >> On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: >>> Chris Angelico writes: >>> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__pete...@web.de> wrote: > > Hm, what does -- and what should -- > >>>

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
On 12/07/2017 12:24 PM, Peter Otten wrote: identity((a, b, c)) calls identity() with one argument whereas identity(a, b, c) calls identity() with three arguments. That's certainly an effect; you just undo it with your test for len(args) == 1. That means that your identity() function throws aw

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Chris Angelico
On Fri, Dec 8, 2017 at 7:25 AM, Ned Batchelder wrote: > On 12/7/17 2:41 PM, Ethan Furman wrote: >> >> On 12/07/2017 11:23 AM, Ned Batchelder wrote: >>> >>> On 12/7/17 1:28 PM, Ethan Furman wrote: >> >> --> identity('spam', 'eggs', 7) ('spam', 'eggs', 7) >>> >>> >>> I don't see why this l

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ned Batchelder
On 12/7/17 2:41 PM, Ethan Furman wrote: On 12/07/2017 11:23 AM, Ned Batchelder wrote: On 12/7/17 1:28 PM, Ethan Furman wrote: --> identity('spam', 'eggs', 7) ('spam', 'eggs', 7) I don't see why this last case should hold.  Why does the function take more than one argument?  And if it does,

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Peter Otten
Ethan Furman wrote: > On 12/07/2017 10:53 AM, Peter Otten wrote: >> Ethan Furman wrote: >> >>> The simple answer is No, and all the answers agree on that point. >>> >>> It does beg the question of what an identity function is, though. >>> >>> My contention is that an identity function is a do-noth

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Nathan Ernst
There is a built-in identity function in Python. The function is called 'id'. See https://docs.python.org/3/library/functions.html#id Note that this will not behave the same across different Python runtimes. e.g. CPython, IronPython or Jython all implement this differently. An example: Python 3.5

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
On 12/07/2017 11:46 AM, Paul Moore wrote: On 7 December 2017 at 18:28, Ethan Furman wrote: The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. My contention is that an identity function is a do-nothing function th

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Paul Moore
On 7 December 2017 at 18:28, Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
On 12/07/2017 11:23 AM, Ned Batchelder wrote: On 12/7/17 1:28 PM, Ethan Furman wrote: --> identity('spam', 'eggs', 7) ('spam', 'eggs', 7) I don't see why this last case should hold. Why does the function take more than one argument? And if it does, then why doesn't it work like this?

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Chris Angelico
On Fri, Dec 8, 2017 at 6:29 AM, Lele Gaifax wrote: > Chris Angelico writes: > >> On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__pete...@web.de> wrote: >>> >>> Hm, what does -- and what should -- >>> >>> identity(('spam', 'eggs', 7)) >>> >>> produce? >> >> The same thing. And so should identity(((

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Lele Gaifax
Chris Angelico writes: > On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__pete...@web.de> wrote: >> >> Hm, what does -- and what should -- >> >> identity(('spam', 'eggs', 7)) >> >> produce? > > The same thing. And so should identity((('spam', 'eggs', 7))) and > identity'spam', 'eggs', 7 and

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ned Batchelder
On 12/7/17 1:28 PM, Ethan Furman wrote: The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. My contention is that an identity function is a do-nothing function that simply returns what it was given: --> identity(

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
On 12/07/2017 10:53 AM, Peter Otten wrote: Ethan Furman wrote: The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. My contention is that an identity function is a do-nothing function that simply returns what it wa

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Chris Angelico
On Fri, Dec 8, 2017 at 5:53 AM, Peter Otten <__pete...@web.de> wrote: > Ethan Furman wrote: > >> The simple answer is No, and all the answers agree on that point. >> >> It does beg the question of what an identity function is, though. >> >> My contention is that an identity function is a do-nothing

Re: Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Peter Otten
Ethan Furman wrote: > The simple answer is No, and all the answers agree on that point. > > It does beg the question of what an identity function is, though. > > My contention is that an identity function is a do-nothing function that > simply returns what it was given: > > --> identity(1) > 1

Stackoverflow question: Is there a built-in identity function in Python?

2017-12-07 Thread Ethan Furman
The simple answer is No, and all the answers agree on that point. It does beg the question of what an identity function is, though. My contention is that an identity function is a do-nothing function that simply returns what it was given: --> identity(1) 1 --> identity('spam') 'spam' --> ide