mh | 29 Aug 01:17

[1,2,3] exactly same as [1,2,3,] ?

x=[1,2,3]
and
x=[1,2,3,]

are exactly the same, right?

I'm generating some python data, and it's less error prone
to not treat the last element specially, but I want to be
sure I'm generating an equivalent data structure.

Many TIA!
Mark

--

-- 
Mark Harrison
Pixar Animation Studios
--
http://mail.python.org/mailman/listinfo/python-list

Paul McNett | 29 Aug 01:28
Favicon
Gravatar

Re: [1,2,3] exactly same as [1,2,3,] ?

mh <at> pixar.com wrote:
> x=[1,2,3]
> and
> x=[1,2,3,]
> 
> are exactly the same, right?

When confronted with this type of question, I ask the interpreter:

{{{
mac:~ pmcnett$ python
Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
 >>> [1,2,3] == [1,2,3,]
True
}}}

Paul
--
http://mail.python.org/mailman/listinfo/python-list

James Mills | 29 Aug 01:35

Re: [1,2,3] exactly same as [1,2,3,] ?

On Fri, Aug 29, 2008 at 9:28 AM, Paul McNett <p <at> ulmcnett.com> wrote:
> When confronted with this type of question, I ask the interpreter:
>
> {{{
> mac:~ pmcnett$ python
> Python 2.5.2 (r252:60911, Feb 22 2008, 07:57:53)
> [GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
> Type "help", "copyright", "credits" or "license" for more information.
>>>> [1,2,3] == [1,2,3,]
> True
> }}}

I must point out though that although they contain
the same elements/data, they are not the same
object/instance.

{{{
#!python
>>> x = [1, 2, 3]
>>> y = [1, 2, 3]
>>> id(x)
3083095148L
>>> id(y)
3082953324L
>>> x == y
True
}}}

If you view the documentation for a list:
{{{
(Continue reading)

Paul McNett | 29 Aug 01:40
Favicon
Gravatar

Re: [1,2,3] exactly same as [1,2,3,] ?

James Mills wrote:
> I must point out though that although they contain
> the same elements/data, they are not the same
> object/instance.

True, but the OP wanted equality:

 > I want to be
 > sure I'm generating an equivalent data structure.

Paul
--
http://mail.python.org/mailman/listinfo/python-list

Terry Reedy | 29 Aug 07:43

Re: [1,2,3] exactly same as [1,2,3,] ?


mh <at> pixar.com wrote:
> x=[1,2,3]
> and
> x=[1,2,3,]
> 
> are exactly the same, right?

Yes, so you can write something like either your second example or

l = [
   kjasldfjs,
   kjsalfj,
   ksjdflasj,
]

and insert items without worrying about leaving out the comma (less of a 
problem with 'horizontal' list), or delete the last line and not have to 
worry about deleting the comma on the line before.

--
http://mail.python.org/mailman/listinfo/python-list

Ken Starks | 29 Aug 11:09

Re: [1,2,3] exactly same as [1,2,3,] ?

mh <at> pixar.com wrote:
> x=[1,2,3]
> and
> x=[1,2,3,]
> 
> are exactly the same, right?
> 
> I'm generating some python data, and it's less error prone
> to not treat the last element specially, but I want to be
> sure I'm generating an equivalent data structure.
> 
> Many TIA!
> Mark
> 
 >>> x=[1,2,3,]
 >>> repr(x)
[1,2,3]

--
http://mail.python.org/mailman/listinfo/python-list


Gmane