Antonio Caminero Garcia wrote:
> On Friday, January 6, 2017 at 6:04:33 AM UTC-8, Peter Otten wrote:
>> Example: you are looking for the minimum absolute value in a series of
>> integers. As soon as you encounter the first 0 it's unnecessary extra
>> work to check the remaining values, but the buil
On Friday, January 6, 2017 at 6:04:33 AM UTC-8, Peter Otten wrote:
> Example: you are looking for the minimum absolute value in a series of
> integers. As soon as you encounter the first 0 it's unnecessary extra work
> to check the remaining values, but the builtin min() will continue.
>
> The s
Jussi Piitulainen writes:
> It could still be added as an option, to both takewhile and iter(_, _).
That's too messy, it really should be pervasive in iterators.
--
https://mail.python.org/mailman/listinfo/python-list
Peter Otten <__pete...@web.de> writes:
> return min(take_until(), key=firstitem)[1]
Actually, key=abs should work. I realized that after posting.
--
https://mail.python.org/mailman/listinfo/python-list
Paul Rubin writes:
> I think Python's version of iterators is actually buggy and at least
> the first element of the rest of the sequence should be preserved.
> There are ways to fake it but they're too messy for something like
> this. It should be the default and might have been a good change fo
Paul Rubin writes:
> Jussi Piitulainen writes:
>> That would return 0 even when there is no 0 in xs at all.
>
> Doesn't look that way to me:
>
> >>> minabs([5,3,1,2,4])
> 1
Sorry about that. I honestly meant to say it would return 1 even when
there was a single 0 at the very end. Somehow
Paul Rubin wrote:
> Paul Rubin writes:
>> seems to work, but is ugly. Maybe there's something better.
>
> def minabs2(xs):
> def z():
> for x in xs:
> yield abs(x), x
> if x==0: break
> return min(z())[1]
>
> is the same thing but
Paul Rubin writes:
> seems to work, but is ugly. Maybe there's something better.
def minabs2(xs):
def z():
for x in xs:
yield abs(x), x
if x==0: break
return min(z())[1]
is the same thing but a little bit nicer.
--
https://mail.py
Paul Rubin writes:
> Doesn't look that way to me:
> >>> minabs([5,3,1,2,4])
> 1
There's a different problem though:
>>> minabs([1,2,3,0])
1
I think Python's version of iterators is actually buggy and at least the
first element of the rest of the sequence should be preserved. Th
Jussi Piitulainen writes:
> That would return 0 even when there is no 0 in xs at all.
Doesn't look that way to me:
>>> minabs([5,3,1,2,4])
1
--
https://mail.python.org/mailman/listinfo/python-list
Pablo Lucena writes:
> How about using the second usage of builtin iter()?
>
> In [92]: iter?
> Docstring:
> iter(iterable) -> iterator
> iter(callable, sentinel) -> iterator
Nice to learn about that. But it has the same problem as
itertools.takewhile:
> In [88]: numbers
> Out[88]: [1, 9, 8, 11,
Paul Rubin writes:
> Jussi Piitulainen writes:
>>> Use itertools.takewhile
>> How? It consumes the crucial stop element:
>
> Oh yucch, you're right, it takes it from both sides. How about this:
>
> from itertools import takewhile, islice
> def minabs(xs):
> a = iter(xs)
> m =
Jussi Piitulainen writes:
>> Use itertools.takewhile
> How? It consumes the crucial stop element:
Oh yucch, you're right, it takes it from both sides. How about this:
from itertools import takewhile, islice
def minabs(xs):
a = iter(xs)
m = min(map(abs,takewhile(lambda x:
How about using the second usage of builtin iter()?
In [92]: iter?
Docstring:
iter(iterable) -> iterator
iter(callable, sentinel) -> iterator
Get an iterator from an object. In the first form, the argument must
supply its own iterator, or be a sequence.
*In the second form, the callable is calle
Rustom Mody writes:
> On a Saturday, Jussi Piitulainen wrote:
[snip]
>> You switched to a simpler operator. Would Haskell notice that
>>
>>def minabs(x, y): return min(x, y, key = abs)
>>
>> has a meaningful zero? Surely it has its limits somewhere and then
>> the programmer needs to supply
On Saturday, January 7, 2017 at 1:42:47 PM UTC+5:30, Jussi Piitulainen wrote:
> Rustom Mody writes:
>
> > On Saturday, Jussi Piitulainen wrote:
> >> Paul Rubin writes:
> >>
> >> > Peter Otten writes:
> >> >> How would you implement stopmin()?
> >> >
> >> > Use itertools.takewhile
> >>
> >> How?
Peter Otten wrote:
> Example: you are looking for the minimum absolute value in a series of
> integers. As soon as you encounter the first 0 it's unnecessary extra work
> to check the remaining values, but the builtin min() will continue.
>
> The solution is a minimum function that allows the use
Steve D'Aprano wrote:
> On Sat, 7 Jan 2017 01:04 am, Peter Otten wrote:
>
>> Example: you are looking for the minimum absolute value in a series of
>> integers. As soon as you encounter the first 0 it's unnecessary extra
>> work to check the remaining values, but the builtin min() will continue.
Paul Rubin wrote:
> Peter Otten <__pete...@web.de> writes:
>> How would you implement stopmin()?
>
> Use itertools.takewhile
I should have mentioned that I had already run into that -- let's call it --
off-by-one bug.
--
https://mail.python.org/mailman/listinfo/python-list
Wolfgang Maier wrote:
> On 1/6/2017 15:04, Peter Otten wrote:
>> Example: you are looking for the minimum absolute value in a series of
>> integers. As soon as you encounter the first 0 it's unnecessary extra
>> work to check the remaining values, but the builtin min() will continue.
>>
>> The sol
Jussi Piitulainen wrote:
> Peter Otten writes:
>
>> Example: you are looking for the minimum absolute value in a series of
>> integers. As soon as you encounter the first 0 it's unnecessary extra
>> work to check the remaining values, but the builtin min() will continue.
>>
>> The solution is a m
On Sat, 7 Jan 2017 07:06 am, Wolfgang Maier wrote:
> On 1/6/2017 15:04, Peter Otten wrote:
[...]
>> How would you implement stopmin()?
>>
>
> How about:
>
> def stopmin (iterable, key, stop):
> def take_until ():
> for e in iterable:
> yield e
> if key(e)
Chris Angelico writes:
> On Sat, Jan 7, 2017 at 7:12 PM, Jussi Piitulainen wrote:
>> You switched to a simpler operator. Would Haskell notice that
>>
>>def minabs(x, y): return min(x, y, key = abs)
>>
>> has a meaningful zero? Surely it has its limits somewhere and then
>> the programmer need
On Sat, Jan 7, 2017 at 7:12 PM, Jussi Piitulainen
wrote:
> You switched to a simpler operator. Would Haskell notice that
>
>def minabs(x, y): return min(x, y, key = abs)
>
> has a meaningful zero? Surely it has its limits somewhere and then the
> programmer needs to supply the information.
If
Rustom Mody writes:
> On Saturday, Jussi Piitulainen wrote:
>> Paul Rubin writes:
>>
>> > Peter Otten writes:
>> >> How would you implement stopmin()?
>> >
>> > Use itertools.takewhile
>>
>> How? It consumes the crucial stop element:
>>
>>it = iter('what?')
>>list(takewhile(str.isalpha,
On Sat, 7 Jan 2017 01:04 am, Peter Otten wrote:
> Example: you are looking for the minimum absolute value in a series of
> integers. As soon as you encounter the first 0 it's unnecessary extra work
> to check the remaining values, but the builtin min() will continue.
>
> The solution is a minimum
On Saturday, January 7, 2017 at 12:26:04 PM UTC+5:30, Jussi Piitulainen wrote:
> Paul Rubin writes:
>
> > Peter Otten writes:
> >> How would you implement stopmin()?
> >
> > Use itertools.takewhile
>
> How? It consumes the crucial stop element:
>
>it = iter('what?')
>list(takewhile(str.i
Paul Rubin writes:
> Peter Otten writes:
>> How would you implement stopmin()?
>
> Use itertools.takewhile
How? It consumes the crucial stop element:
it = iter('what?')
list(takewhile(str.isalpha, it)) # ==> ['w', 'h', 'a', 't']
next(it, 42) # ==> 42
--
https://mail.python.org/mailman/
Peter Otten <__pete...@web.de> writes:
> How would you implement stopmin()?
Use itertools.takewhile
--
https://mail.python.org/mailman/listinfo/python-list
On 1/6/2017 15:04, Peter Otten wrote:
Example: you are looking for the minimum absolute value in a series of
integers. As soon as you encounter the first 0 it's unnecessary extra work
to check the remaining values, but the builtin min() will continue.
The solution is a minimum function that allo
Peter Otten writes:
> Example: you are looking for the minimum absolute value in a series of
> integers. As soon as you encounter the first 0 it's unnecessary extra work
> to check the remaining values, but the builtin min() will continue.
>
> The solution is a minimum function that allows the u
Example: you are looking for the minimum absolute value in a series of
integers. As soon as you encounter the first 0 it's unnecessary extra work
to check the remaining values, but the builtin min() will continue.
The solution is a minimum function that allows the user to specify a stop
value:
32 matches
Mail list logo