In article pan.2009.06.09.03.18...@remove.this.cybersource.com.au,
But practicality beats purity -- there are many scenarios where we make
compromises in our meaning in order to get correct, efficient code. E.g.
we use floats, despite them being a poor substitute for the abstract Real
numbers we
Albert van der Horst alb...@spenarnc.xs4all.nl writes:
But I greatly prefer a set
for i in {point1,point2,point3}:
statements
Agreed, for the reasons you cite. I think this idiom can be expected to
become more common and hopefully displace using a tuple literal or
Gunter Henriksen wrote:
[ ... ]
I guess to me, fundamentally, the interpretation of
tuple as a sequence whose elements have semantic meaning
implicitly defined by position is a relatively abstract
intrepretation whose value is dubious relative to the
value of immutability, since it seems like
Mel mwil...@the-wire.com writes:
The immutability makes it easier to talk about the semantic meanings.
After you do
event_timestamp = (2009, 06, 04, 05, 02, 03)
there's nothing that can happen to the tuple to invalidate
(year, month, day, hour, minute, second) = event_timestamp
En Tue, 09 Jun 2009 05:02:33 -0300, Steven D'Aprano
ste...@remove.this.cybersource.com.au escribió:
[...] As tuples are defined in Python, they quack like immutable lists,
they
walk like immutable lists, and they swim like immutable lists. Why
shouldn't we treat them as immutable lists?
[In this tuple]
dodge_city = (1781, 1870, 1823)
(population, feet_above_sea_level, establishment_year) = dodge_city
each index in the sequence implies something very
different about each value. The semantic meaning
of each index is *more* than just the position in
the sequence; it
Gunter Henriksen gunterhenrik...@gmail.com writes:
I think I would have difficulty holding a position that this should
not be a class (or equivalent via namedtuple()) or a dict. It seems to
me like a case could be made that there are far more situations where
it makes sense to use tuples as
Try, then, this tuple:
event_timestamp = (2009, 06, 04, 05, 02, 03)
(year, month, day, hour, minute, second) = event_timestamp
A list would be wrong for this value, because each position in the
sequence has a specific meaning beyond its mere sequential position. Yet
it also matters
Gunter Henriksen gunterhenrik...@gmail.com writes:
Try, then, this tuple:
event_timestamp = (2009, 06, 04, 05, 02, 03)
(year, month, day, hour, minute, second) = event_timestamp
I totally agree about anything to do with immutability, I think the
relative ordering of the elements
event_timestamp = (2009, 06, 04, 05, 02, 03)
(year, month, day, hour, minute, second) = event_timestamp
[...]
The point of each position having a different semantic meaning is that
tuple unpacking works as above. You need to know the meaning of each
position in order to unpack
On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote:
Use a list when the semantic meaning of an item doesn't depend on all
the other items: it's “only” a collection of values.
Your list of message codes is a good example: if a value appears at
index 3, that doesn't make it mean something
On Jun 8, 10:06 pm, Chris Rebert c...@rebertia.com wrote:
On Mon, Jun 8, 2009 at 6:57 PM, samwysesamw...@gmail.com wrote:
On Jun 8, 7:37 pm, Carl Banks pavlovevide...@gmail.com wrote:
On Jun 8, 4:43 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
m...@pixar.com writes:
Is there any
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
On Tue, 09 Jun 2009 09:43:45 +1000, Ben Finney wrote:
Use a list when the semantic meaning of an item doesn't depend on
all the other items: it's “only” a collection of values.
Your list of message codes is a good example:
On Jun 9, 12:30 am, Emile van Sebille em...@fenx.com wrote:
On 6/8/2009 8:43 PM Ben Finney said...
The fact that literal set syntax is a relative newcomer is the primary
reason for that, I'd wager.
Well, no. It really is more, that's odd... why use set?
Until I ran some timing tests this
On Jun 9, 4:57 am, samwyse samw...@gmail.com wrote:
On Jun 8, 8:57 pm, samwyse samw...@gmail.com wrote:
I conclude that using constructors is generally a bad idea, since the
compiler doesn't know if you're calling the builtin or something with
an overloaded name. I presume that the
On Jun 9, 8:20 am, samwyse samw...@gmail.com wrote:
On Jun 9, 12:30 am, Emile van Sebille em...@fenx.com wrote:
On 6/8/2009 8:43 PM Ben Finney said...
The fact that literal set syntax is a relative newcomer is the primary
reason for that, I'd wager.
Well, no. It really is more,
John Machin sjmac...@lexicon.net wrote:
T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T)
I've learned a lot from this thread, but this is the
niftiest bit I've picked up... thanks!
--
Mark Harrison
Pixar Animation Studios
--
Steven D'Aprano wrote:
James Tauber explains this at
URL:http://jtauber.com/blog/2006/04/15/
python_tuples_are_not_just_constant_lists/.
He doesn't really explain anything though, he merely states it as
revealed wisdom. The closest he comes to an explanation is to declare
that in tuples
m...@pixar.com wrote:
John Machin sjmac...@lexicon.net wrote:
T=lambda x:x in(25401,25402,25408);import dis;dis.dis(L);dis.dis(T)
I've learned a lot from this thread, but this is the
niftiest bit I've picked up... thanks!
If you are doing a lot of dissing, starting with
from dis import dis
On Tue, 09 Jun 2009 04:57:48 -0700, samwyse wrote:
Time to test things! I'm going to compare three things using Python
3.0:
X={...}\nS=lambda x: x in X
S=lambda x: x in {...}
S=lambda x: x in (...)
where the ... is replaced by lists of integers of various lengths.
Here's the test
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
I'm currently using [], but only coz I think it's prettier
than ().
context: these are database errors and e is database
On Mon, Jun 8, 2009 at 2:36 PM, m...@pixar.com wrote:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
I'm currently using [], but only coz I think it's prettier
than ().
m...@pixar.com wrote:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
I'm currently using [], but only coz I think it's prettier
than ().
context: these are database errors and
mh at pixar.com writes:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
From the viewpoint of relative execution speed, in the above case
if it matters at all it
m...@pixar.com writes:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
I'm currently using [], but only coz I think it's prettier
than ().
Use a list when the semantic
On Jun 8, 4:43 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
m...@pixar.com writes:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if e.message.code in (25401,25402,25408):
I'm currently using [], but only
Carl Banks pavlovevide...@gmail.com writes:
If you want to go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order
nor does it make sense to list any item twice.
Yes, a set would be best for this specific situation.
I don't
On Jun 8, 6:02 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
Carl Banks pavlovevide...@gmail.com writes:
If you want to go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order
nor does it make sense to list any item twice.
On Jun 8, 7:37 pm, Carl Banks pavlovevide...@gmail.com wrote:
On Jun 8, 4:43 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
m...@pixar.com writes:
Is there any reason to prefer one or the other of these statements?
if e.message.code in [25401,25402,25408]:
if
On Jun 8, 2009, at 9:28 PM, Carl Banks wrote:
On Jun 8, 6:02 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
Carl Banks pavlovevide...@gmail.com writes:
If you want to go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order
nor
On Mon, Jun 8, 2009 at 6:57 PM, samwysesamw...@gmail.com wrote:
On Jun 8, 7:37 pm, Carl Banks pavlovevide...@gmail.com wrote:
On Jun 8, 4:43 pm, Ben Finney ben+pyt...@benfinney.id.au wrote:
m...@pixar.com writes:
Is there any reason to prefer one or the other of these statements?
On Tue, 09 Jun 2009 11:02:54 +1000, Ben Finney wrote:
Carl Banks pavlovevide...@gmail.com writes:
If you want to go strictly by the book, I would say he ought to be
using a set since his collection of numbers has no meaningful order nor
does it make sense to list any item twice.
Yes, a
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
In addition, using a tuple or a list in this context:
if e.message.code in (25401,25402,25408):
is so idiomatic, that using a set in it's place would be distracting.
I think a list in that context is fine, and that's the
On 6/8/2009 8:43 PM Ben Finney said...
Steven D'Aprano ste...@remove.this.cybersource.com.au writes:
In addition, using a tuple or a list in this context:
if e.message.code in (25401,25402,25408):
is so idiomatic, that using a set in it's place would be distracting.
I think a list in
34 matches
Mail list logo