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
Steven D'Aprano wrote, on January 07, 2017 10:43 PM
>
> On Sunday 08 January 2017 16:39, Deborah Swanson wrote:
>
> > What I've done so far:
> >
> > with open('E:\\Coding projects\\Pycharm\\Moving\\Moving
> 2017 in.csv',
> > 'r') as infile:
> > ls = list(csv.reader(infile))
> > lst = na
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
Deborah Swanson wrote:
> to do that is with .fget(). Believe me, I tried every possible way to
> use instance.A or instance[1] and no way could I get ls[instance.A].
Sorry, no.
To get a list of namedtuple instances use:
rows = csv.reader(infile)
Record = namedtuple("Record", next(rows))
records
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
Peter Otten wrote, on January 08, 2017 3:01 AM
>
> Deborah Swanson wrote:
>
> > to do that is with .fget(). Believe me, I tried every > possible way
to
> > use instance.A or instance[1] and no way could I get ls[instance.A].
>
> Sorry, no.
I quite agree, I was describing the dead end I was in
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 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
Deborah Swanson wrote:
> Peter Otten wrote, on January 08, 2017 3:01 AM
>>
>> Deborah Swanson wrote:
>>
>> > to do that is with .fget(). Believe me, I tried every > possible way
> to
>> > use instance.A or instance[1] and no way could I get ls[instance.A].
>>
>> Sorry, no.
>
> I quite agree, I
Peter Otten wrote, on January 08, 2017 5:21 AM
>
> Deborah Swanson wrote:
>
> > Peter Otten wrote, on January 08, 2017 3:01 AM
> >>
> >> Deborah Swanson wrote:
> >>
> >> > to do that is with .fget(). Believe me, I tried every > possible
> >> > way
> > to
> >> > use instance.A or instance[1] an
"Deborah Swanson" writes:
> Peter Otten wrote, on January 08, 2017 3:01 AM
>>
>> columnA = [record.A for record in records]
>
> This is very neat. Something like a list comprehension for named tuples?
Not something like - this *is* a list comprehension - it creates a list
of named tuples.
The
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
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
Paul Rudin wrote, on January 08, 2017 6:49 AM
>
> "Deborah Swanson" writes:
>
> > Peter Otten wrote, on January 08, 2017 3:01 AM
> >>
> >> columnA = [record.A for record in records]
> >
> > This is very neat. Something like a list comprehension for named
> > tuples?
>
> Not something like - t
On Samstag, 7. Januar 2017 19:07:55 Clint Moyer wrote:
> I would lightly advise against, assuming both Pip and your package
> manager are trying to accomplish nearly the same thing. Stick with
> updating through the repo.
>
> If you find that the version your OS provides is out-of-date compared
>
Steven D'Aprano wrote, on January 07, 2017 11:37 PM
>
> Grumpy, an experimental project from Google, transpiles
> Python code into Go, allowing Python programs to be compiled
> and run as static binaries using the Go toolchain.
>
>
>
http://www.infoworld.com/article/3154624/application-develo
On 01/08/2017 06:18 PM, Deborah Swanson wrote:
> (haha, unless
> you ask)
C'mon, go for it ... there hasn't been a good rant here in
4 or 5 minutes ...
--
https://mail.python.org/mailman/listinfo/python-list
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
Tim Daneliuk wrote, on January 08, 2017 4:49 PM
>
> On 01/08/2017 06:18 PM, Deborah Swanson wrote:
> > (haha, unless
> > you ask)
>
> C'mon, go for it ... there hasn't been a good rant here in
> 4 or 5 minutes ...
Oh hell. (How do I tell him I was up til 8am this morning, only got a
few hours sl
On Sunday 08 January 2017 20:53, Deborah Swanson wrote:
> Steven D'Aprano wrote, on January 07, 2017 10:43 PM
>>
>> On Sunday 08 January 2017 16:39, Deborah Swanson wrote:
>>
>> > What I've done so far:
>> >
>> > with open('E:\\Coding projects\\Pycharm\\Moving\\Moving
>> 2017 in.csv',
>> > 'r')
Suppose you have an expensive calculation that gets used two or more times in a
loop. The obvious way to avoid calculating it twice in an ordinary loop is with
a temporary variable:
result = []
for x in data:
tmp = expensive_calculation(x)
result.append((tmp, tmp+1))
But what if you ar
On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano
wrote:
> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
>
>
> I can't decide whether that's an awesome trick or a horrible hack...
A horrible hack on par with abusing a recursive function's arguments
for private variables. Much
On Monday 09 January 2017 15:09, Chris Angelico wrote:
> On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano
> wrote:
>> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
>>
>>
>> I can't decide whether that's an awesome trick or a horrible hack...
>
> A horrible hack on par with
On Mon, Jan 9, 2017 at 3:49 PM, Steven D'Aprano
wrote:
> Helper functions are good. Helper functions that are only used
> *once* are a code smell. *LOTS* of helper functions that are only used once
> are
> a sign that something is horrible, and it might just be your language...
Agreed, but with
On Monday, January 9, 2017 at 10:19:31 AM UTC+5:30, Steven D'Aprano wrote:
> On Monday 09 January 2017 15:09, Chris Angelico wrote:
>
> > On Mon, Jan 9, 2017 at 2:53 PM, Steven D'Aprano wrote:
> >> [(tmp, tmp + 1) for x in data for tmp in [expensive_calculation(x)]]
> >>
> >>
> >> I can't decide w
On 1/5/2017 7:48 PM, Michael Torrie wrote:
> While Python can do that, using a web framework to process HTTP requests
> and generate HTML to display in the browser, I don't believe Python is
> the appropriate language for the task at hand. Most web sites that do
> interactive formula calculations
Steven D'Aprano wrote, on January 07, 2017 10:43 PM
>
> On Sunday 08 January 2017 16:39, Deborah Swanson wrote:
>
> The recommended way is with the _replace method:
>
> py> instance._replace(A=999)
> Record(A=999, B=20, C=30)
> py> instance._replace(A=999, C=888)
> Record(A=999, B=20, C=888)
>
Peter Otten wrote, on January 08, 2017 5:21 AM
>
> Deborah Swanson wrote:
>
> > Peter Otten wrote, on January 08, 2017 3:01 AM
>
> Personally I would recommend against mixing data (an actual location)
and
> metadata (the column name,"Location"), but if you wish my code can be
> adapted as fol
Steven D'Aprano wrote, on January 08, 2017 7:30 PM
>
> On Sunday 08 January 2017 20:53, Deborah Swanson wrote:
>
> > Steven D'Aprano wrote, on January 07, 2017 10:43 PM
>
> No, I'm pretty sure that's not the case. I don't have access
> to your CSV file,
> but I can simulate it:
>
> ls = [['Lo
30 matches
Mail list logo