Re: Style for docstring

2022-04-23 Thread jan via Python-list
"return true iff this".

I like this.

jan

On 23/04/2022, Stefan Ram  wrote:
> Rob Cliffe  writes:
>>I'm curious as to why so many people prefer "Return" to "Returns".
>
>   The commands, er, names of functions, use the imperative mood
>   ("print", not "prints"). So, "return" aligns with that mood
>   as a paraphrase of such names.
>
>   In Java, at one point, they decided to start to use the
>   third person at one point and then half-heartedly converted
>   all the documentation, as in
>
> |void println(boolean x)
> |Prints a boolean and then terminate the line.
>
>   , where they modified "print" but did not bother do modify
>   "terminate".
>
>   And instead of "return true if this, false if not this",
>   I might be inclined to write "return true iff this".
>
>   BTW: As a language element that helps to construct a boolean
>   expression from a file name, some languages, like SQL, use
>   "EXISTS", while others, like MS-DOS-batch, use "EXIST".
>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: new sorting algorithm

2022-05-02 Thread jan via Python-list
Hi,

> The median-of-three partitioning technique makes that work reasonably
well, so it won't be pathologically slow

Just to be clear because I've wondered but haven't looked into it, we
know naive quicksorting of already-sorted data is pathalogical, but
median-of-3 is known to fix this pathology?

cheers

jan

On 02/05/2022, Chris Angelico  wrote:
> On Mon, 2 May 2022 at 09:20, Dan Stromberg  wrote:
>>
>>
>> On Sun, May 1, 2022 at 1:44 PM Chris Angelico  wrote:
>>>
>>> On Mon, 2 May 2022 at 06:43, Dan Stromberg  wrote:
>>> > On Sun, May 1, 2022 at 11:10 AM Chris Angelico 
>>> > wrote:
>>> >>
>>> >> On Mon, 2 May 2022 at 01:53, Nas Bayedil  wrote:
>>> >> > We believe that using this method to develop completely new, fast
>>> >> > algorithms, approaching the speed of the famous *QuickSort*, the
>>> >> > speed of
>>> >> > which cannot be surpassed, but its drawback can be circumvented, in
>>> >> > the
>>> >> > sense of stack overflow, on some data.
>>> >>
>>> >> Hmm, actually TimSort *does* exceed the speed of quicksort for a lot
>>> >> of real-world data. For instance, if you take a large sorted list,
>>> >> append a handful of (unsorted) items to it, and then sort the list,
>>> >> TimSort can take advantage of the fact that the bulk of the list is
>>> >> sorted. It ends up significantly faster than re-sorting the entire
>>> >> list.
>>> >
>>> >
>>> > In fact, Timsort is O(n) for already-sorted data, while many quicksorts
>>> > are O(n^2) for already-sorted data.
>>> >
>>> > Quicksort can be salvaged by using a median-of-3 partitioning, but it's
>>> > still O(n^2) in the (less common) worst case.
>>> >
>>>
>>> This is true, but purely sorted data isn't a very practical case. The
>>> case of mostly-sorted data IS practical, though, so it's a quite big
>>> win that it can be close to O(n), and still faster than inserting each
>>> item individually.
>>
>>
>> You seem to be of the impression that nearly-sorted data isn't an uphill
>> battle with a straightforward quicksort.
>>
>> I'm having a hard time convincing myself of that.
>>
>
> The median-of-three partitioning technique makes that work reasonably
> well, so it won't be pathologically slow. It's hardly Quicksort's best
> feature, but it could easily be a lot worse. I'd have to check, but I
> think it still manages to be O(n log n). Merge sort, of course, is a
> lot more consistent, but the asymptotic cost is still broadly the
> same.
>
> But Timsort manages to be close to O(n) for sorted data, reversed
> data, nearly-sorted or nearly-reversed data, etc. Makes it very handy
> for jobs like "click a heading to sort by it", where you might add
> multiple sort keys.
>
> (Plus, Python's implementation has some cool tricks for small
> collections that make it quite efficient.)
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Python install failing. Install log is available.

2021-05-20 Thread jan via Python-list
Hi,

I've usually had problems installing python, typically pip breaking.

This time it's simply not installing correctly when run as
administrator, and not at all when run as non-administrator.

As administrator, it's not installing for other users as I believe it should.

It's certainly not adding the python path correctly *for all users*
(install option "add python to environment variables"), from a command
console run as admin:

C:\WINDOWS\system32>whoami
antik\administrator

C:\WINDOWS\system32>echo %PATH%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\dotnet\;C:\Program
Files\TortoiseGit\bin;C:\Users\Administrator\AppData\Local\Programs\Python\Python39\Scripts\;C:\Users\Administrator\AppData\Local\Programs\Python\Python39\;C:\Users\Administrator\AppData\Local\Microsoft\WindowsApps;C:\Users\Administrator\.dotnet\tools

It's there, but from a non-admin console (I work just a normal user):

C:\Users\jan>whoami
antik\jan

C:\Users\jan>echo %path%
C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\;C:\Program
Files\dotnet\;C:\Program
Files\TortoiseGit\bin;C:\Users\jan\AppData\Local\Microsoft\WindowsApps;C:\Users\jan\AppData\Local\Programs\Git\cmd

So no python path added.

When install is run as non-administrator it seems to fail outright due
to lack of privileges.  The install log for this non-admin is
available on request (I'd rather not attach it as it contain have
sensitive info, but can post it publicly if really wanted. It's 60K).

I tried elevating my non-admin account to admin then re-running the
python installer, it broke.

Trying to reinstall it has now lost all associations with the .py
extension. I don't know what's going on.

My build depends on python and obviously that's failing now.  I've
worked around it by downloading and unzipping python embedded, setting
the file association and hardcoding file paths, but that's certainly
not ideal.

Any thoughts?

Using python-3.9.5-amd64.exe, OS is win 2016 server eval, fresh install.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Python install failing. Install log is available.

2021-05-21 Thread jan via Python-list
OK, but

1. should the installer work for administrator + all users or not?

2. if not, should the installer work for me (a non-admin) and install
python correctly and successfully for my account if I run it in my
account, not the admin?

thanks

jan

On 20/05/2021, Terry Reedy  wrote:
> On 5/20/2021 7:06 AM, jan via Python-list wrote:
>
>> This time it's simply not installing correctly when run as
>> administrator, and not at all when run as non-administrator.
>>
>> As administrator, it's not installing for other users as I believe it
>> should.
>>
>> It's certainly not adding the python path correctly *for all users*
>
>> C:\WINDOWS\system32>whoami
> ...
>> Any thoughts?
>
> On Windows, use the py launcher to launch python.  It was added as the
> solution to problems with adding python paths, including problems with
> multiple installs and those with removing them.
>
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Terminology: EU language skills, and Master to Main (or ...)

2021-06-13 Thread jan via Python-list
Hi,
see below

On 13/06/2021, dn via Python-list  wrote:
> [to folk subscribed to both the Python list and Python-Tutor: apologies
> for cross-posting]
>
>
> Regarding levels of skill or complexity in learning, the European Union
> has been working on "The Common European Framework of Reference for
> Languages: Learning, Teaching, Assessment". It also standardises
> terminology for spoken/national-language training courses.
> https://en.wikipedia.org/wiki/Common_European_Framework_of_Reference_for_Languages

To re-state what you already said but I didn't pick up on, this is
natural spoken languages.

[snip]

>
> A group at the King Juan-Carlos University (Madrid, Spain) is collecting
> practitioners' opinions in a bid to categorise Python mastery according
> to the Framework. You may like to contribute by responding to their
> research surveys (one form takes five-minutes, the other fifteen):
> https://docs.google.com/forms/d/e/1FAIpQLSdlzWGpvZHLHXl6iEdHbLTB6QvYXknrD9-JKmzY7riYJkPmNw/viewform

Also I'm not sure there's much to relate artificial (programming)
languages with natural (spoken) ones.

'Mastery; of python programming is almost meaningless because if you
are a decent programmer you will be able to pick up new paradigms
*reasonably* straightforwardly, and paradignms thus internalised
(functional/OO/procedural/logic/etc) will then transfer fairly easily
across languages.

Also it's about problem solving which is an independent skill altogether.

Also it includes transferrable prior experiences and
knowledge/exposure ("IThere's a library for that" / "regexps are a
trap here" / "just use a parser generator, don't write it by hand" /
"The largest element every time? Let me introduce you to the Heap data
structure" / "if you stick a bloom filter in front of that you can cut
out 90% of database accesses here")

If you're a good scala programmer it will take only a few weeks to get
up to speed with python - I've done it. Most of that time went on
learning the libraries (of python, and scala) anyway.

>
>
> I like to label tutorials and conference-talks (and sometimes individual
> slides/sections) to indicate levels of complexity. However, have
> replaced abstract terms such as "Beginner" or "Junior", "Intermediate",
> and "Advanced" or "Senior" which all sound school-ish; with the three
> terms: "Apprentice", "Journeyman", and "Master" (see also
> https://leanpub.com/b/python-craftsman).

Just words.

>
[snip]

>
> There is a potential-problem in the rising sensitivity of the word
> "Master", eg the git CVS has replaced the idea of a Master-branch with
> "Main branch" (or user-chosen alternative name). Will referring to
> skilled professionals as 'masters (of their profession/craft)'
> transgress (international or at least US-instigated) 'Political
> Correctness'?

I've never seen any of this at my workplaces. When I occasionally read
about this on the web and follow up to the source posts of those doing
this, my impression is there are a few, vocal people who are just
there to disrupt rather than do anything constructive.
That may be reporting bias though so my view may be of questionable reliability.

Basically I've not seen much if any value in this PC stuff.

>
>
> What do you think a professionally-recognisable series of skill-levels
> for programmers?

Fine. If you can do it in any meaningful sense.

jan

>
> --
> Regards,
> =dn
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Optimizing Small Python Code

2021-06-24 Thread jan via Python-list
If I'm not mistaken, the original output is O(n^2) in quantity of
chars, and as output time is proportional to the length of the output,
that makes the output time also O(n^2) here too.

So I guess this only looks like it's reduced to linear because the
output here is very small. For large n it would become obvious.

jan

On 24/06/2021, Avi Gross via Python-list  wrote:
> Yes, I agree that if you do not need to show your work to a human, then the
> problem specified could be solved beforeand and a simple print statement
> would suffice.
>
> Ideally you want to make a problem harder such as by specifying an N that
> varies then testing it with an arbitrary N.
>
> But I suggest the item below is not minimal. You can store the printout
> more
> compactly as the only symbols out put are tabs, newlines and seven digits.
> If your language supported some function that expanded a binary string that
> used say 4 bytes per symbol so it could be printed, or accepted a
> compressed
> form of the string and uncompressed it, you might have code like:
>
> print(unzip("n*n&&S!~se"))
>
> -Original Message-
> From: Python-list  On
> Behalf Of Michael F. Stemper
> Sent: Wednesday, June 23, 2021 10:23 AM
> To: python-list@python.org
> Subject: Re: Optimizing Small Python Code
>
> On 23/06/2021 08.17, Stefan Ram wrote:
>> "Avi Gross"  writes:
>>> This can be made a one-liner too! LOL!
>>
>> print( '1\n  0\n2\n  0\n  1\n3\n  0\n  1\n
>> 2\n4\n
> 0\n  1\n  2\n  3\n5\n  0\n  1\n  2\n  3\n
> 4\n6\n  0\n  1\n  2\n  3\n  4\n  5\n' )
>
> Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1). That
> deserves a Turing award or something.
>
> --
> Michael F. Stemper
> You can lead a horse to water, but you can't make him talk like Mr. Ed by
> rubbing peanut butter on his gums.
> --
> https://mail.python.org/mailman/listinfo/python-list
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: Optimizing Small Python Code

2021-06-24 Thread jan via Python-list
You're right, I was making an academic point.

I think this whole compression question relates to Kolmogorov
complexity 

"In algorithmic information theory (a subfield of computer science and
mathematics), the Kolmogorov complexity of an object, such as a piece
of text, is the length of a shortest computer program (in a
predetermined programming language) that produces the object as
output".

cheers

jan

On 24/06/2021, Avi Gross via Python-list  wrote:
> Jan,
>
> As an academic discussion, yes, many enhancements only pay off when things
> are larger.
>
> And for most purposes, I/O is so much slower that it makes little
> difference. But on a multi-processing machine, extra CPU may impact how much
> else the machine can do at the same time.
>
> Here is an example of what I meant. Given exactly the current output, what
> is the shorter program you can use to cheat and produce an answer.
>
> Recall the original output has a length of 169:
>
> a = """1
>   0
> 2
>   0
>   1
> 3
>   0
>   1
>  2
> 4
> 0
>   1
>   2
>   3
> 5
>   0
>   1
>   2
>   3
> 4
> 6
>   0
>   1
>   2
>   3
>   4
>   5
>   """
>
> len(a)
>
>
> Now if you had already used a compression algorithm on it, you would get
> this:
>
> import zlib
> a = zlib.compress(a.encode("ascii"))
> len(a)
>
> Now a has a length of 53!
>
> It now looks like this:
>
> b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j
> \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7'
>
> So the shorter cheat program might now be:
>
 print(zlib.decompress(b'x\x9c3\xe4R\x00\x03\x03.#8\x0bB\x1br\x19c\x88(\x18q\x99p!q\xc1\x00\xa6\xd1\x98\xcb\x14S\x03\x9a\n\x13.3\x82j
 \xb4\t\x94\x86\x99\t\x00\xdc\x87\x14\xb7').decode("ASCII"))
> 1
>   0
> 2
>   0
>   1
> 3
>   0
>   1
>  2
> 4
> 0
>   1
>   2
>   3
> 5
>   0
>   1
>   2
>   3
> 4
> 6
>   0
>   1
>   2
>   3
>   4
>   5
>
> Of course, the above has overhead as you have a line to import the library
> as well as the darn function names but for larger amounts of text, those
> stay fixed.
>
> I note again this won't fool humans but some on-line courses that just take
> your program and run it and only compare the output will be fooled.
>
>
> -Original Message-
> From: jan 
> Sent: Thursday, June 24, 2021 3:01 AM
> To: Avi Gross 
> Cc: python-list@python.org
> Subject: Re: Optimizing Small Python Code
>
> If I'm not mistaken, the original output is O(n^2) in quantity of chars, and
> as output time is proportional to the length of the output, that makes the
> output time also O(n^2) here too.
>
> So I guess this only looks like it's reduced to linear because the output
> here is very small. For large n it would become obvious.
>
> jan
>
> On 24/06/2021, Avi Gross via Python-list  wrote:
>> Yes, I agree that if you do not need to show your work to a human,
>> then the problem specified could be solved beforeand and a simple
>> print statement would suffice.
>>
>> Ideally you want to make a problem harder such as by specifying an N
>> that varies then testing it with an arbitrary N.
>>
>> But I suggest the item below is not minimal. You can store the
>> printout more compactly as the only symbols out put are tabs, newlines
>> and seven digits.
>> If your language supported some function that expanded a binary string
>> that used say 4 bytes per symbol so it could be printed, or accepted a
>> compressed form of the string and uncompressed it, you might have code
>> like:
>>
>> print(unzip("n*n&&S!~se"))
>>
>> -Original Message-
>> From: Python-list
>>  On Behalf Of
>> Michael F. Stemper
>> Sent: Wednesday, June 23, 2021 10:23 AM
>> To: python-list@python.org
>> Subject: Re: Optimizing Small Python Code
>>
>> On 23/06/2021 08.17, Stefan Ram wrote:
>>> "Avi Gross"  writes:
 This can be made a one-liner too! LOL!
>>>
>>> print( '1\n  0\n2\n  0\n  1\n3\n  0\n  1\n
>>> 2\n4\n
>> 0\n  1\n  2\n  3\n5\n  0\n  1\n  2\n  3\n
>> 4\n6\n  0\n  1\n  2\n  3\n  4\n  5\n' )
>>
>> Unless I'm figuring ot wrong, you just took it from O(n^2) to O(1).
>> That deserves a Turing award or something.
>>
>> --
>> Michael F. Stemper
>> You can lead a horse to water, but you can't make him talk like Mr. Ed
>> by rubbing peanut butter on his gums.
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>
>
> --
> https://mail.python.org/mailman/listinfo/python-list
>
-- 
https://mail.python.org/mailman/listinfo/python-list