On Dec 12, 7:51 am, Marco Mariani wrote:
> Filip Gruszczyński wrote:
> > I am not doing it, because I need it. I can as well use "if not elem
> > is None",
>
> I suggest "if elem is not None", which is not quite the same.
They are semantically the same. In theory, Filip's would run slower
becaus
Scott David Daniels:
> If you want to keep the original's method, but do it in a more Pythonic
> way, I would suggest:
>
> def deNone4(alist):
> j = 0
> for val in alist:
> if val is not None:
> alist[j] = val
> j += 1
>
On Mon, 2008-12-15 at 02:11 +, Lie Ryan wrote:
> On Fri, 12 Dec 2008 22:55:20 +, Steven D'Aprano wrote:
>
> > On Fri, 12 Dec 2008 21:18:36 +, Lie Ryan wrote:
> >> Personally, I'd prefer VB's version:
> >> foo IsNot bar
> >>
> >> or in pseudo-python
> >> foo isnot bar
> >>
> >> since
Steven D'Aprano wrote:
On Fri, 12 Dec 2008 19:02:24 -0500, Terry Reedy wrote:
...
Tim Chase wrote:
If you want to literally remove None objects from a list(or
mutable sequence)
def deNone(alist):
n=len(alist)
i=j=0
while i < n:
if alist[i] is not None:
alist[j] = alist
On Mon, 15 Dec 2008 05:39:45 +, Lie Ryan wrote:
> I was just expressing the
> preference that operators should be composed of a single word,
> especially since none of the other operators are multi-words
Then you should have said so, instead of introducing red-herrings about
tired programmer
Lie Ryan writes:
> I was just expressing the preference that operators should be
> composed of a single word, especially since none of the other
> operators are multi-words (Special cases aren't special enough to
> break the rules). The only advantage of using 'is not' over 'isnot' is
> that we
On Mon, 15 Dec 2008 03:21:21 +, Steven D'Aprano wrote:
> On Mon, 15 Dec 2008 02:11:10 +, Lie Ryan wrote:
>
>>> So given the normal precedence rules of Python, there is no ambiguity.
>>> True, you have to learn the rules, but that's no hardship.
>>
>> *I* know about the precedence rule, b
On Mon, 15 Dec 2008 02:11:10 +, Lie Ryan wrote:
>> So given the normal precedence rules of Python, there is no ambiguity.
>> True, you have to learn the rules, but that's no hardship.
>
> *I* know about the precedence rule, but a newbie or a tired programmer
> might not. He might want to reve
On Fri, 12 Dec 2008 22:55:20 +, Steven D'Aprano wrote:
> On Fri, 12 Dec 2008 21:18:36 +, Lie Ryan wrote:
>> Personally, I'd prefer VB's version:
>> foo IsNot bar
>>
>> or in pseudo-python
>> foo isnot bar
>>
>> since that would make it less ambiguous.
>
> "a is not b" is no more ambiguo
On 2008-12-12, Filip Gruszczyński wrote:
> Hi!
>
> I would like to iterate over a sequence nad ignore all None objects.
> The most obvious way is explicitly checking if element is not None,
> but it takes too much space. And I would like to get something faster.
> I can use
> [ sth for sth in self
On Sat, 13 Dec 2008 06:00:09 -0800, bearophileHUGS wrote:
> Steven D'Aprano:
>> The algorithm is unclear: try explaining what you are doing in English,
>> and see how difficult it is.
>
> That algorithm is a standard one, and quite clear. Any programmer worth
> his/her/hir salt has to be able to
On Sat, 13 Dec 2008 11:07:53 +, Steven D'Aprano wrote:
> Now, sure, most of the work in Tim's version is executed in fast C code
> instead of slow Python code.
Say what???
I'm sorry, I must have been smoking crack when I wrote that. It does
nothing of the sort. Tim's version is pure Python.
Steven D'Aprano:
> The algorithm is unclear: try explaining
> what you are doing in English, and see how difficult it is.
That algorithm is a standard one, and quite clear. Any programmer
worth his/her/hir salt has to be able to understand that.
I agree that the idiom with the list comp (algorith
Just to be clear, I decided to use generator by alex23, as it seems
simple, short and understandable. Still reading this thread was quite
interesting, thanks :-)
--
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list
On Fri, 12 Dec 2008 19:02:24 -0500, Terry Reedy wrote:
> Tim Chase wrote:
>>> If you want to literally remove None objects from a list(or
>>> mutable sequence)
>>>
>>> def deNone(alist):
>>>n=len(alist)
>>>i=j=0
>>>while i < n:
>>> if alist[i] is not None:
>>>alist[j]
Tim Chase wrote:
If you want to literally remove None objects from a list(or
mutable sequence)
def deNone(alist):
n=len(alist)
i=j=0
while i < n:
if alist[i] is not None:
alist[j] = alist[i]
j += 1
i += 1
alist[j:i] = []
blist=[None,1,None,2,None,3,None,
Filip Gruszczyński wrote:
I don't mean memory, but space in code ;-)
Your goal should be clarity of code, not saving keystrokes. Writing
something that is compact in terms of the amount of code to write does
not mean its function is clear or even that it is more efficient to run,
for that
On Fri, 12 Dec 2008 21:18:36 +, Lie Ryan wrote:
> On Fri, 12 Dec 2008 11:50:38 -0500, Steve Holden wrote:
>
>> Kirk Strauser wrote:
>>> At 2008-12-12T15:51:15Z, Marco Mariani writes:
>>>
Filip Gruszczyński wrote:
> I am not doing it, because I need it. I can as well use "if no
On Fri, 12 Dec 2008 10:08:23 -0600, Kirk Strauser wrote:
> At 2008-12-12T15:51:15Z, Marco Mariani writes:
>
>> Filip Gruszczyński wrote:
>>
>>> I am not doing it, because I need it. I can as well use "if not elem
>>> is None",
>
>> I suggest "if elem is not None", which is not quite the same.
>
If you want to literally remove None objects from a list(or mutable
sequence)
def deNone(alist):
n=len(alist)
i=j=0
while i < n:
if alist[i] is not None:
alist[j] = alist[i]
j += 1
i += 1
alist[j:i] = []
blist=[None,1,None,2,None,3,None,None,4,None]
deNon
If you want to literally remove None objects from a list(or mutable
sequence)
def deNone(alist):
n=len(alist)
i=j=0
while i < n:
if alist[i] is not None:
alist[j] = alist[i]
j += 1
i += 1
alist[j:i] = []
blist=[None,1,None,2,None,3,None,None,4,None]
deNone(blist)
On Fri, 12 Dec 2008 11:50:38 -0500, Steve Holden wrote:
> Kirk Strauser wrote:
>> At 2008-12-12T15:51:15Z, Marco Mariani writes:
>>
>>> Filip Gruszczyński wrote:
>>>
I am not doing it, because I need it. I can as well use "if not elem
is None",
>>
>>> I suggest "if elem is not None",
alex23 writes:
> Rather than a list comprehension, use a generator expression:
>
> for item in (x for x in sequence if x is not None):
>do_something(x)
I much prefer
for item in sequence:
if x is not None:
do_something(x)
--
Arnaud
--
http://mail.python.org/mailman/listinfo/py
Kirk Strauser wrote:
> At 2008-12-12T15:51:15Z, Marco Mariani writes:
>
>> Filip Gruszczyński wrote:
>>
>>> I am not doing it, because I need it. I can as well use "if not elem
>>> is None",
>
>> I suggest "if elem is not None", which is not quite the same.
>
> So what's the difference exactly?
Kirk Strauser wrote:
At 2008-12-12T15:51:15Z, Marco Mariani writes:
Filip Gruszczyński wrote:
I am not doing it, because I need it. I can as well use "if not elem
is None",
I suggest "if elem is not None", which is not quite the same.
So what's the difference exactly? "foo is not None"
Kirk Strauser wrote:
So what's the difference exactly? "foo is not None" is actually surprising
to me, since "not None" is True. "0 is True" is False, but "0 is not None"
is True. Why is that?
Cause I was tired of course, and got the not precedente not right!! Argh
--
http://mail.python.org
At 2008-12-12T15:51:15Z, Marco Mariani writes:
> Filip Gruszczyński wrote:
>
>> I am not doing it, because I need it. I can as well use "if not elem
>> is None",
> I suggest "if elem is not None", which is not quite the same.
So what's the difference exactly? "foo is not None" is actually surp
On Fri, 12 Dec 2008 16:51:15 +0100, Marco Mariani wrote:
> Filip Gruszczyński wrote:
>
>
>> I am not doing it, because I need it. I can as well use "if not elem is
>> None",
>
> I suggest "if elem is not None", which is not quite the same.
In which way is it not the same? Has the same behavio
Filip Gruszczyński wrote:
I am not doing it, because I need it. I can as well use "if not elem
is None",
I suggest "if elem is not None", which is not quite the same.
If you slip such an error in a post, I suggest to practice some time
writing correct code before having one-liner contests w
Filip Gruszczyński wrote:
> I checked itertools, but the only thing that
> seemed ok, was ifilter - this requires seperate function though, so
> doesn't seem too short.
is this too much long?
>>> from itertools import ifilter
>>> for element in ifilter(lambda x: x is not None, [0,1,2,None,3,Non
On Dec 12, 8:08 am, "Filip Gruszczyński" wrote:
> I am not doing it, because I need it. I can as well use "if not elem
> is None", but I just wanted to know, if there is some better way of
> doing this. I like to know :-)
>
> And I can't understand why you are becoming so aggressive because of
> t
Filip Gruszczyński wrote:
> Hi!
>
> I would like to iterate over a sequence nad ignore all None objects.
> The most obvious way is explicitly checking if element is not None,
> but it takes too much space. And I would like to get something faster.
> I can use
> [ sth for sth in self.__sth if not s
I am not doing it, because I need it. I can as well use "if not elem
is None", but I just wanted to know, if there is some better way of
doing this. I like to know :-)
And I can't understand why you are becoming so aggressive because of
this. Just because I asked for that, doesn't mean, that I wil
On Fri, 12 Dec 2008 10:18:35 +0100, Filip Gruszczyński
wrote:
> Hi!
>
> I would like to iterate over a sequence nad ignore all None objects. The
> most obvious way is explicitly checking if element is not None, but it
> takes too much space.
Too much space???
seq = [x for x in seq if x is not N
2008/12/12 Filip Gruszczyński :
> I don't mean memory, but space in code ;-)
Trying to save printer paper for your listings, then?
--
Tim Rowe
--
http://mail.python.org/mailman/listinfo/python-list
I don't mean memory, but space in code ;-)
I'll try this generator :)
--
Filip Gruszczyński
--
http://mail.python.org/mailman/listinfo/python-list
On Dec 12, 7:18 pm, "Filip Gruszczyński" wrote:
> Hi!
>
> I would like to iterate over a sequence nad ignore all None objects.
> The most obvious way is explicitly checking if element is not None,
> but it takes too much space. And I would like to get something faster.
> I can use
> [ sth for sth
Filip Gruszczyński wrote:
I would like to iterate over a sequence nad ignore all None objects.
The most obvious way is explicitly checking if element is not None,
but it takes too much space.
That doesn't make much sense; why would iterating over the sequence take
more _space_?
--
Erik Max
38 matches
Mail list logo