Re: list comprehension problem

2009-11-03 Thread Scott David Daniels
Terry Reedy wrote: What immutability has to do with identity is that 'two' immutable objects with the same value *may* actually be the same object, *depending on the particular version of a particular implementation*. t1 = (1,2,3) # an immutable object t2 = (1,2,3) # another immutable objec

Re: list comprehension problem

2009-11-03 Thread Ben Finney
Paul Rudin writes: > Falcolas writes: > > > [s.strip() for s in hosts if s.strip()] > > There's something in me that rebels against seeing the same call > twice. Agreed. I'd probably use: >>> lines = ["foo", " ", " bar ", "", "baz"] >>> [s for s in (s.strip() for s in lines) if s]

Re: list comprehension problem

2009-11-02 Thread Paul Rudin
Falcolas writes: > [s.strip() for s in hosts if s.strip()] There's something in me that rebels against seeing the same call twice. I'd probably write: filter(None, (s.strip() for s in hosts)) -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension problem

2009-11-02 Thread Krister Svanlund
On Mon, Nov 2, 2009 at 10:11 PM, Aahz wrote: > In article > <7589e0a1-98b2-4df4-bc76-5d4c10194...@f20g2000prn.googlegroups.com>, > Falcolas   wrote: >> >>I'd also recommend trying the following filter, since it is identical >>to what you're trying to do, and will probably catch some additional >>

Re: list comprehension problem

2009-11-02 Thread Aahz
In article <7589e0a1-98b2-4df4-bc76-5d4c10194...@f20g2000prn.googlegroups.com>, Falcolas wrote: > >I'd also recommend trying the following filter, since it is identical >to what you're trying to do, and will probably catch some additional >edge cases without any additional effort from you. > >[s.

Re: list comprehension problem

2009-11-01 Thread Mel
Steven D'Aprano wrote: > (6) Metaphoric equivalence: > Kali is death. > Life is like a box of chocolates. OK to here, but this one switches between metaphor and simile, and arguably, between identity and equality. Mel. -- http://mail.python.org/mailman/listinfo/python-list

Re: list comprehension problem

2009-11-01 Thread Cousin Stanley
> > There are an infinite number of empty sets > that differ according to their construction: > > The set of all fire-breathing mammals. > Apparently, you have never been a witness to someone who recently ingested one of Cousin Chuy's Super-Burritos .. :-) -- Stan

Re: list comprehension problem

2009-11-01 Thread Mick Krippendorf
Steven D'Aprano wrote: > On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: >> >> (Ax)(x is a fire-breathing animal <-> x is a real number equal to >> sqrt(-1)). >> >> And since there are neither such things, it follows that s1 = s2. > > That assumes that all({}) is defined as true. That

Re: list comprehension problem

2009-11-01 Thread Steven D'Aprano
On Sun, 01 Nov 2009 21:32:15 +0100, Mick Krippendorf wrote: > When we want find out if two sets s1 and s2 are the same we only need to > look at their extensions, so given: > > (i s1)(Ay)(y e s1 <-> y is a fire-breathing animal) (i s2)(Ay)(y e s2 > <-> y is a real number equal to sqrt(-1)) >

Re: list comprehension problem

2009-11-01 Thread Mick Krippendorf
Steven D'Aprano wrote: > There are an infinite number of empty sets that differ according to their > construction: > > The set of all American Presidents called Boris Nogoodnik. > The set of all human languages with exactly one noun and one verb. > The set of all fire-breathing mammals. > The set

Re: list comprehension problem

2009-10-31 Thread Steven D'Aprano
On Sat, 31 Oct 2009 14:12:40 -0400, Terry Reedy wrote: > alex23 wrote: >> Terry Reedy wrote: >>> alex23 wrote: You're completely wrong. Immutability has nothing to do with identity, > ... > > I'm honestly not getting your point here. > > Let me try again, a bit differently. > > I cla

Re: list comprehension problem

2009-10-31 Thread Terry Reedy
alex23 wrote: Terry Reedy wrote: alex23 wrote: You're completely wrong. Immutability has nothing to do with identity, ... > I'm honestly not getting your point here. Let me try again, a bit differently. I claim that the second statement, and therefor the first, can be seen as wrong. I also

Re: list comprehension problem

2009-10-30 Thread alex23
Terry Reedy wrote: > alex23 wrote: > > You're completely wrong. Immutability has nothing to do with identity, > > which is what 'is' is testing for: > > What immutability has to do with identity is that 'two' immutable > objects with the same value *may* actually be the same object, > *depending o

Re: list comprehension problem

2009-10-30 Thread Ben Finney
(Please preserve attribution lines when you quote someone, so we can keep track of who said what in the developing discussion.) Nick Stinemates writes: > > Some objects are singletons, ie there's only ever one of them. The > > most common singleton is None. In virtually every other case you > >

Re: list comprehension problem

2009-10-29 Thread Terry Reedy
alex23 wrote: On Oct 30, 1:10 pm, Nick Stinemates wrote: Some objects are singletons, ie there's only ever one of them. The most common singleton is None. In virtually every other case you should be using "==" and "!=". Please correct me if I am wrong, but I believe you meant to say some objec

Re: list comprehension problem

2009-10-29 Thread Steven D'Aprano
On Thu, 29 Oct 2009 23:10:39 -0400, Nick Stinemates wrote: >> Some objects are singletons, ie there's only ever one of them. The most >> common singleton is None. In virtually every other case you should be >> using "==" and "!=". > > Please correct me if I am wrong, but I believe you meant to sa

Re: list comprehension problem

2009-10-29 Thread alex23
On Oct 30, 1:10 pm, Nick Stinemates wrote: > > Some objects are singletons, ie there's only ever one of them. The most > > common singleton is None. In virtually every other case you should be > > using "==" and "!=". > > Please correct me if I am wrong, but I believe you meant to say some > objec

Re: list comprehension problem

2009-10-29 Thread Nick Stinemates
> Some objects are singletons, ie there's only ever one of them. The most > common singleton is None. In virtually every other case you should be > using "==" and "!=". Please correct me if I am wrong, but I believe you meant to say some objects are immutable, in which case you would be correct.

Re: list comprehension problem

2009-10-29 Thread Bruno Desthuilliers
mk a écrit : Hello everyone, print hosts ['9.156.44.227\n', '9.156.46.34 \n', '\n'] Just for the record, where did you get this "hosts" list from ? (hint : depending on the answer, there might be a way to avoid having to filter out the list) -- http://mail.python.org/mailman/listinfo/py

Re: list comprehension problem

2009-10-29 Thread Bruno Desthuilliers
Falcolas a écrit : (snip) > I'd also recommend trying the following filter, since it is identical to what you're trying to do, and will probably catch some additional edge cases without any additional effort from you. [s.strip() for s in hosts if s.strip()] The problem with this expression is

Re: list comprehension problem

2009-10-29 Thread Falcolas
On Oct 29, 9:31 am, "Diez B. Roggisch" wrote: > mk wrote: > > Hello everyone, > > > print hosts > > hosts = [ s.strip() for s in hosts if s is not '' and s is not None and > > s is not '\n' ] > > print hosts > > > ['9.156.44.227\n', '9.156.46.34 \n', '\n'] > > ['9.156.44.227', '9.156.46.34', ''] >

Re: list comprehension problem

2009-10-29 Thread MRAB
Diez B. Roggisch wrote: mk wrote: Hello everyone, print hosts hosts = [ s.strip() for s in hosts if s is not '' and s is not None and s is not '\n' ] print hosts ['9.156.44.227\n', '9.156.46.34 \n', '\n'] ['9.156.44.227', '9.156.46.34', ''] Why does the hosts list after list comprehension st

Re: list comprehension problem

2009-10-29 Thread Diez B. Roggisch
mk wrote: > Hello everyone, > > print hosts > hosts = [ s.strip() for s in hosts if s is not '' and s is not None and > s is not '\n' ] > print hosts > > ['9.156.44.227\n', '9.156.46.34 \n', '\n'] > ['9.156.44.227', '9.156.46.34', ''] > > Why does the hosts list after list comprehension still c

Re: list comprehension problem

2009-10-29 Thread Gary Herron
mk wrote: Hello everyone, print hosts hosts = [ s.strip() for s in hosts if s is not '' and s is not None and s is not '\n' ] print hosts ['9.156.44.227\n', '9.156.46.34 \n', '\n'] ['9.156.44.227', '9.156.46.34', ''] Why does the hosts list after list comprehension still contain '' in last

list comprehension problem

2009-10-29 Thread mk
Hello everyone, print hosts hosts = [ s.strip() for s in hosts if s is not '' and s is not None and s is not '\n' ] print hosts ['9.156.44.227\n', '9.156.46.34 \n', '\n'] ['9.156.44.227', '9.156.46.34', ''] Why does the hosts list after list comprehension still contain '' in last position?