RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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) >

Re: Python for WEB-page !?

2017-01-08 Thread Eric S. Johansson
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

Re: Temporary variables in list comprehensions

2017-01-08 Thread Rustom Mody
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

Re: Temporary variables in list comprehensions

2017-01-08 Thread Chris Angelico
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

Re: Temporary variables in list comprehensions

2017-01-08 Thread Steven D'Aprano
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

Re: Temporary variables in list comprehensions

2017-01-08 Thread Chris Angelico
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

Temporary variables in list comprehensions

2017-01-08 Thread Steven D'Aprano
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Steven D'Aprano
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')

RE: Grumpy: Python to Go compiler

2017-01-08 Thread Deborah Swanson
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

Re: Grumpy: Python to Go compiler

2017-01-08 Thread Tim Daneliuk
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Antonio Caminero Garcia
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

RE: Grumpy: Python to Go compiler

2017-01-08 Thread Deborah Swanson
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

Re: Using sudo with pip3?

2017-01-08 Thread Hans-Peter Jansen
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 >

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
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

Re: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Paul Rudin
"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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Jussi Piitulainen
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Peter Otten
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Peter Otten
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
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

RE: Using namedtuples field names for column indices in a list of lists

2017-01-08 Thread Deborah Swanson
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

Re: Search a sequence for its minimum and stop as soon as the lowest possible value is found

2017-01-08 Thread Paul Rubin
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