Re: A question on modification of a list via a function invocation
Am 17.08.2017 um 02:14 schrieb Ned Batchelder: On Thu, Aug 17, 2017 at 8:29 AM, Mok-Kong Shen wrote: Anyway, while any new user of a programming language certainly can be expected to take good efforts to learn a lot of new stuffs, I suppose it's good for any practical programming language to minimize the cases of surprises for those that come from other programming languages. Which other languages? Should Python's functions act like C functions, or like Haskell functions? Should Python's strings act like C strings, or Ruby strings? Should Python's syntax be like C syntax, or like Lisp syntax? If languages can't be different from each other, then there's no point in having different languages. I agree that gratuitous differences are, well, gratuitous, but the name/value data model of Python is not some trivial detail that we could change to match some other language: it's a fundamental part of what makes Python what it is. For some reason, students have been taught that things can be either call-by-reference or call-by-value. But those are not the only two possibilities, and neither completely describes how Python works. Learn Python for what it is. Your last sentence is fine and certainly to be accepted. Is there a good document with which one could well use to resolve problems like the present one? (Earlier I learned a few programming languages from their ISO standard documents, which was not easy but later turned out to be quite profitable.) M. K. Shen expect that there be a good documen -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 17.08.2017 um 02:41 schrieb Steve D'Aprano: On Thu, 17 Aug 2017 08:29 am, Mok-Kong Shen wrote: I have earlier learned some other (older) programming languages. For these the formal parameters are either "by reference" or "by value". By reference and by value are not the only two conventions. Perhaps if you go back to the 1950s you might be able to argue that "reference" and "value" are the only two conventions, but alternatives have existed for many decades, since *at least* 1960 when Algol introduced "call by name". Python's evaluation strategy has existed for at least 43 years since Barbara Liskov named the calling convention used by CLU "call by sharing" in 1974. (It actually is much older than CLU, it goes back all the way to Lisp.) https://en.wikipedia.org/wiki/Evaluation_strategy#Call_by_sharing In the first case, any modification of the formal parameter Technically, you cannot modify the formal parameter, because the formal parameter is just a name unbound to any value. It's just the label in the function definition. You need to have actually passed a value as argument to the function before there is anything to modify. inside a function affects the corresponding actual parameter of a function call, while in the second case a copy of the actual parameter is passed into the function so that any modification of the formal parameter inside the function has no effect at all outside. This is extremely clear-cut in comparison to Python, isn't it? Python (and Ruby, Scheme, Ocaml, etc) are very clear-cut too. Just different. This may help: http://import-that.dreamwidth.org/1130.html Anyway, while any new user of a programming language certainly can be expected to take good efforts to learn a lot of new stuffs, I suppose it's good for any practical programming language to minimize the cases of surprises for those that come from other programming languages. Indeed. And call by value is surprising: why should passing a giant array of a million values make a copy of the array just because I pass it to a function? And call by reference is even more surprising: if I assign a value to a local name inside a function, why should it modify names in the caller's namespace? Python's evaluation strategy is the least surprising of all the calling strategies I've used. Sorry for my poor capacity to comprehend. I read in the web page you cited: "In Python, the parameters to a function or method are always local to that function or method. Any assignments to local variables inside the function only affect the local variable, not the caller's variable." But then why in my test2 the global list does get modified? (Would alist[0]=3 etc. be "in-place modification" while alist=[30,60,90] is deemed not an "in-place modification"? If yes, where is that term clearly defined? (That term is new for me.) M. K. Shen M. K. Shen M. K. -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 17.08.2017 um 01:58 schrieb Cameron Simpson: On 17Aug2017 01:03, Mok-Kong Shen <mok-kong.s...@t-online.de> wrote: Am 17.08.2017 um 00:39 schrieb Chris Angelico: On Thu, Aug 17, 2017 at 8:29 AM, Mok-Kong Shen <mok-kong.s...@t-online.de> wrote: Chris wrote: objects exist independently of names, and names refer to objects. If you do "x = y", you're saying "figure out which object 'y' means, and make the name 'x' refer to it". If you do "x[1] = y", you're saying "figure out which object 'y' means, and tell the object that 'x' means that it should make [1] refer to that object". So if you have multiple names referring to the same object, any change you ask that object to do will be seen by every other name that also refers to it - because it's all about the object. I may have misunderstood you. But I don't think what you wrote above would explain why the program below produces the output: [1, 2, 3] [3, 6, 9] M. K. Shen - def test2(alist): alist[0],alist[1],alist[2]=3,6,9 alist=[30,60,90] return This is because "alist" in the function test2 is a _local_ variable. It is a reference to the same list whose reference was passed to the function. So: alist[0],alist[1],alist[2]=3,6,9 This modifies the references within that list. alist=[30,60,90] This makes the local name "alist" refer to a shiny new list [30,60,90], totally unrelated to the list whose reference was first passed in. Importantly, in the main program "ss" still refers to the original list, which now has references to the values 3, 6 and 9 in it. def test3(alist): alist=[30,60,90] alist[0],alist[1],alist[2]=3,6,9 return This code first points "alist" to a new, unrelated, list. Then modifies the references inside that list. Put different values in this function (by using the same values as in test2 you can see whether changes came from one or the other) eg use 5,6,7 or something. ss=[1,2,3] test3(ss) print(ss) test2(ss) print(ss) So test3 first discards its reference to the [1,2,3] list, then modifies an unrelate new list. So "ss" is unchanged, still holding [1,2,3]. Then test modifies the original list (affecting what "ss" holds) and then points its local "alist" at something else (another shiny new list). But that doesn't change what "ss" refers to, so it now has [3,6,9]. I don't yet understand. Why (by which rule of the language reference) should "alist=[30,60,90]" mean discarding the name's reference to the [1,2,3] list? What I conjecture is that in test2 the assignment "alist[0], ..." can only have a proper meaning according to the syntacs of Python if alist is meant to be the global alist. But then, since now the name alist is known to be global, why then in the next line of test2 the name is suddenly interpreted to be local? (Which rule of the language reference says that?) That's what I currently continue to wonder. M. K. Shen M. K. Shen to -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 17.08.2017 um 00:39 schrieb Chris Angelico: On Thu, Aug 17, 2017 at 8:29 AM, Mok-Kong Shen <mok-kong.s...@t-online.de> wrote: I have earlier learned some other (older) programming languages. For these the formal parameters are either "by reference" or "by value". In the first case, any modification of the formal parameter inside a function affects the corresponding actual parameter of a function call, while in the second case a copy of the actual parameter is passed into the function so that any modification of the formal parameter inside the function has no effect at all outside. This is extremely clear-cut in comparison to Python, isn't it? Anyway, while any new user of a programming language certainly can be expected to take good efforts to learn a lot of new stuffs, I suppose it's good for any practical programming language to minimize the cases of surprises for those that come from other programming languages. Python has a data model that is neither of the above, but it's simpler in that you have one pattern for everything. Whether you're looking at function parameters, return values, assignment, loops, function definitions, or anything else, the model is exactly the same. And that model is: objects exist independently of names, and names refer to objects. If you do "x = y", you're saying "figure out which object 'y' means, and make the name 'x' refer to it". If you do "x[1] = y", you're saying "figure out which object 'y' means, and tell the object that 'x' means that it should make [1] refer to that object". So if you have multiple names referring to the same object, any change you ask that object to do will be seen by every other name that also refers to it - because it's all about the object. I may have misunderstood you. But I don't think what you wrote above would explain why the program below produces the output: [1, 2, 3] [3, 6, 9] M. K. Shen - def test2(alist): alist[0],alist[1],alist[2]=3,6,9 alist=[30,60,90] return def test3(alist): alist=[30,60,90] alist[0],alist[1],alist[2]=3,6,9 return ss=[1,2,3] test3(ss) print(ss) test2(ss) print(ss) -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 16.08.2017 um 23:20 schrieb Ned Batchelder: On 8/16/17 5:06 PM, Mok-Kong Shen wrote: Am 15.08.2017 um 20:47 schrieb Larry Hudson: [snip] === test2() code == def test2(alist): ss ─┬─> [1, 2, 3] alist ─┘ - ss ─┬─> [3, 6, 9] alist ─┘ - alist = [30, 60, 90]ss ───> [3, 6, 9] alist ───> [30, 60, 90] [snip] The above shows that with , i.e. assigning single values to individual members of alist (with alist[0]=3 etc.) is "principally" different from assigning a whole list to alist (with alist=[30,60,90]). The first operation doesn't affect the connection between ss and alist, while the second separates the connection between ss and alist, as your diagram above clearly indicates. Isn't this kind of convention/rule something that appears to be not quite natural/"logical" to the common users (non-experts)? This kind of question comes up frequently, so you are right, it needs to be learned. But this is true of nearly everything about programming languages, isn't it? Did you take a look at https://nedbatchelder.com/text/names1.html ? It's the best way I know to explain the principles at work here. I looked at your web page but I don't see at which place in it the issue that I deem to be not natural/"logical" above are (anyway concretely) explained. I apologize, if I have overlooked. I have earlier learned some other (older) programming languages. For these the formal parameters are either "by reference" or "by value". In the first case, any modification of the formal parameter inside a function affects the corresponding actual parameter of a function call, while in the second case a copy of the actual parameter is passed into the function so that any modification of the formal parameter inside the function has no effect at all outside. This is extremely clear-cut in comparison to Python, isn't it? Anyway, while any new user of a programming language certainly can be expected to take good efforts to learn a lot of new stuffs, I suppose it's good for any practical programming language to minimize the cases of surprises for those that come from other programming languages. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 15.08.2017 um 20:47 schrieb Larry Hudson: [snip] === test2() code == def test2(alist): ss ─┬─> [1, 2, 3] alist ─┘ - ss ─┬─> [3, 6, 9] alist ─┘ - alist = [30, 60, 90]ss ───> [3, 6, 9] alist ───> [30, 60, 90] [snip] The above shows that with , i.e. assigning single values to individual members of alist (with alist[0]=3 etc.) is "principally" different from assigning a whole list to alist (with alist=[30,60,90]). The first operation doesn't affect the connection between ss and alist, while the second separates the connection between ss and alist, as your diagram above clearly indicates. Isn't this kind of convention/rule something that appears to be not quite natural/"logical" to the common users (non-experts)? M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 14.08.2017 um 22:10 schrieb oliver: It is not a global because accessing an item of a list does not change whether it is global or local. It would only be global if you declared it global via a "global" statement. Can you give an example, that would help determine the issue. If without a global statement, a name is local, then alist[0]=3 should not work globally, if it works at all, in my layman's logic. M. K. Shen On Mon, 14 Aug 2017 at 16:06 Mok-Kong Shen <mok-kong.s...@t-online.de> wrote: Am 14.08.2017 um 21:53 schrieb Ned Batchelder: On 8/14/17 3:21 PM, Mok-Kong Shen wrote: Am 14.08.2017 um 20:50 schrieb Ned Batchelder: On 8/14/17 2:21 PM, Mok-Kong Shen wrote: I ran the attached program and got the following output: [1, 2, 3] [3, 6, 9] I don't understand why the modification doesn't work in the case of test() but does work in the case of test1(). Thanks for your help in advance. M. K. Shen def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) This reassigns the name alist: alist = [3, 6, 9]. That changes the local variable, but cannot affect the caller's variables. This leaves alist as the same object, but reassigns its elements, mutating the list: alist[0] = 3 This talk has more details: https://nedbatchelder.com/text/names1.html I could more or less understand that in test() alist is interpreted as local but in the extended program below in test2() I first write the same as in test1(), after which I logically assume that the name alist is now known as global and then I write alist=[30,60,90] but that doesn't have any effect globally, since I get the output: [1, 2, 3] [3, 6, 9] [3, 6, 9] Could you please explain that? M. K. Shen - def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return def test2(alist): alist[0],alist[1],alist[2]=3,6,9 alist=[30,60,90] return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) test2(ss) print(ss) Your test2 function first mutates the caller's list by assigning alist[0]=3, then it rebinds the local name alist to be a new list. So the caller's list is now [3, 6, 9]. Sorry for my poor knowledge. After the line alist[0]..., what is the status of the name alist? It's now a global name, right? So why in the line following that the name alist would suddenly be interpreted as local? I can't yet fully comprehend the logic behind that. M. K. Shen . -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 14.08.2017 um 21:53 schrieb Ned Batchelder: On 8/14/17 3:21 PM, Mok-Kong Shen wrote: Am 14.08.2017 um 20:50 schrieb Ned Batchelder: On 8/14/17 2:21 PM, Mok-Kong Shen wrote: I ran the attached program and got the following output: [1, 2, 3] [3, 6, 9] I don't understand why the modification doesn't work in the case of test() but does work in the case of test1(). Thanks for your help in advance. M. K. Shen def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) This reassigns the name alist: alist = [3, 6, 9]. That changes the local variable, but cannot affect the caller's variables. This leaves alist as the same object, but reassigns its elements, mutating the list: alist[0] = 3 This talk has more details: https://nedbatchelder.com/text/names1.html I could more or less understand that in test() alist is interpreted as local but in the extended program below in test2() I first write the same as in test1(), after which I logically assume that the name alist is now known as global and then I write alist=[30,60,90] but that doesn't have any effect globally, since I get the output: [1, 2, 3] [3, 6, 9] [3, 6, 9] Could you please explain that? M. K. Shen - def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return def test2(alist): alist[0],alist[1],alist[2]=3,6,9 alist=[30,60,90] return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) test2(ss) print(ss) Your test2 function first mutates the caller's list by assigning alist[0]=3, then it rebinds the local name alist to be a new list. So the caller's list is now [3, 6, 9]. Sorry for my poor knowledge. After the line alist[0]..., what is the status of the name alist? It's now a global name, right? So why in the line following that the name alist would suddenly be interpreted as local? I can't yet fully comprehend the logic behind that. M. K. Shen . -- https://mail.python.org/mailman/listinfo/python-list
Re: A question on modification of a list via a function invocation
Am 14.08.2017 um 20:50 schrieb Ned Batchelder: On 8/14/17 2:21 PM, Mok-Kong Shen wrote: I ran the attached program and got the following output: [1, 2, 3] [3, 6, 9] I don't understand why the modification doesn't work in the case of test() but does work in the case of test1(). Thanks for your help in advance. M. K. Shen def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) This reassigns the name alist: alist = [3, 6, 9]. That changes the local variable, but cannot affect the caller's variables. This leaves alist as the same object, but reassigns its elements, mutating the list: alist[0] = 3 This talk has more details: https://nedbatchelder.com/text/names1.html I could more or less understand that in test() alist is interpreted as local but in the extended program below in test2() I first write the same as in test1(), after which I logically assume that the name alist is now known as global and then I write alist=[30,60,90] but that doesn't have any effect globally, since I get the output: [1, 2, 3] [3, 6, 9] [3, 6, 9] Could you please explain that? M. K. Shen - def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return def test2(alist): alist[0],alist[1],alist[2]=3,6,9 alist=[30,60,90] return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) test2(ss) print(ss) -- https://mail.python.org/mailman/listinfo/python-list
A question on modification of a list via a function invocation
I ran the attached program and got the following output: [1, 2, 3] [3, 6, 9] I don't understand why the modification doesn't work in the case of test() but does work in the case of test1(). Thanks for your help in advance. M. K. Shen def test(alist): alist=[3,6,9] return def test1(alist): alist[0],alist[1],alist[2]=3,6,9 return ss=[1,2,3] test(ss) print(ss) test1(ss) print(ss) -- https://mail.python.org/mailman/listinfo/python-list
ANN: TEXTCOMBINE-SP
An estimate of entropy of English texts is 1.34 bits per letter [1]. This implies that, if the letters are coded into 5 bits, one needs to appropriately combine 4 text files in order to obtain bit sequences of full entropy, since 4*1.34 = 5.36 > 5. The method used in our software is to sum (mod 32) the coded values of a-z (mapped to 0-25) as 5 bits of the corresponding letters of the text files. There are plenty of other schemes for obtaining high quality pseudo-random sequences in practice, e.g. AES in counter mode. However our scheme seems to be much simpler both in the underlying logic (understandability) and in implementation and is thus a viable alternative that one could use/need under circumstances. The software is available at mok-kong-shen.de M. K. Shen [1] T. M. Cover, R. C. King, A Convergent Gambling Estimate of the Entropy of English, IEEE Trans. Inf. Theory, vol. 24, 1978, pp. 413-421. -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: HOMOPHONE-SP
In classical crypto, homophonic substitution attempts to mitigate risks of frequency analysis via employing one-to-many mappings of plaintext characters to ciphertext characters instead of one-to-one mappings. However, constraints of manual processing naturally very severely limit the extent to which the flattening of the frequency distributions of the ciphertext characters could be achieved, which obviously is on the other hand a non-issue for computer processing. I have written a Python code HOMOPHONE-SP for performing homophonic substitution (in combination with transpositions) where, for obtaining higher security, the processing of the individual plaintext characters is chained via borrowing an idea from modern block ciphers. The software is available at http://mok-kong-shen.de M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: How to obtain an up-to-date document of tkinter
Am 20.04.2017 um 08:08 schrieb Terry Reedy: On 4/19/2017 8:09 PM, Mok-Kong Shen wrote: [snip] I ask this question because apparently there are stuffs of tkinter that worked in Python 3.5 but no longer in Python 3.6.1. I don't know of any such. Please see my reply to breamoreboy. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: How to obtain an up-to-date document of tkinter
Am 20.04.2017 um 02:16 schrieb breamore...@gmail.com: On Thursday, April 20, 2017 at 1:09:45 AM UTC+1, Mok-Kong Shen wrote: How could one obtain an up-to-date document of tkinter. I ask this question because apparently there are stuffs of tkinter that worked in Python 3.5 but no longer in Python 3.6.1. https://docs.python.org/3/library/tkinter.html Can you please state what worked in 3.5 but doesn't in 3.6? Yes. In Python V.3.5, I simply had the declaration: from tkinter import * and thereafter I could use in code lines e.g.: messagebox.showerror() However, in Python V.3.6.1, I have to have the declaration: from tkinter import * import tkinter.messagebox and thereafter have to use: tkinter.messagebox.showerror() M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
How to obtain an up-to-date document of tkinter
How could one obtain an up-to-date document of tkinter. I ask this question because apparently there are stuffs of tkinter that worked in Python 3.5 but no longer in Python 3.6.1. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Version 2.1 of my natural language text steganography scheme
Version 2.1 of my natural language text steganography scheme WORDLISTTEXTSTEGANOGRAPHY, having left behind a few initial shortcomings and tiny problems stemming e.g from version incompatibilities of Python, is available on my new home page: http://mok-kong-shen.de. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Correction of announcement of Version 2 of a steganographical software of mine
Due to a new convention of my Internet provider, my current home page is now: http://mokkong-shen.homepage.t-online.de M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Version 2 of my natural language steganographical scheme released
Version 2 of my natural language steganographical scheme WORDLISTTEXTSTEGANOGRAPHY is available on my home page http://mokkong-shen.privat.t-online.de , together with a few other cryptological and steganographical software of mine. See update notes in it for the differences to earlier versions. I regret that in the earlier versions a sentence was unfortunately missing in the explanation of how to do the examples, with the consequence that new users might have difficulties with the examples. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
A comparatively efficient software for embedding secret information bits into nataural language texts
WORDLISTTEXTSTEGANOGRAPHY is a new software (employing an extensive English word list) which, while performing linguistic steganography, also involves pseudo-random separation of the word list into two sublists (for denoting 0 and 1 bits) that are dependent on dynamic session-key materials, thus furnishing simultaneously substantial cryptographical security for the embedded stego bits. The software has a stegobit embedding rate of roughly 0.5 or higher per word of cover-text which the user composes to be as natural as possible under the guidance of the software. To my knowledge there is currently no other linguistic stego software that could compete with it, when both the naturalness of the cover texts and the stegobit embedding rate are taken into consideration as evaluation criteria. The software in Python with a GUI coded in tkinter is available at: http://s13.zetaboards.com/Crypto/topic/9024439/1/ For comments and critiques I should be very grateful. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
ANN: PERMPOLY v1.0 released
PERMPOLYSP is a block cipher (with authentication) with substitutions of bit groups with pseudo-randomly determined permutation polynomials mod 2**n and pseudo-random permutations of bytes. It employs in its algorithm a number of mechanisms with the goal to enhance the dynamics/variability of runtime encryption processing. Available at: http://s13.zetaboards.com/Crypto/topic/7590068/1/ M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Re: A strange list concatenation result
Am 14.08.2016 um 13:06 schrieb ast: [snip] Thanks. The use of id() is very helpful in clarifying what acutally happens in the present case. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: A strange list concatenation result
Am 13.08.2016 um 03:08 schrieb Steven D'Aprano: On Sat, 13 Aug 2016 06:44 am, Mok-Kong Shen wrote: list2 = [1,2,3] list1 += [4,5,6] print(list1, list2) [1, 2, 3, 4, 5, 6] [1, 2, 3] Does that help? I don't yet understand why in my 2nd example list2 came out as [1, 2, 3] outside. Because you assign list2 = [1, 2, 3]. What did you expect it to be? But in my function test() there is a code line "list2=list2+[4,5,6]". Could you kindly explain why this didn't work? M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: A strange list concatenation result
Am 11.08.2016 um 23:49 schrieb Gary Herron: On 08/11/2016 03:06 PM, Mok-Kong Shen wrote: def test(list1,list2): list1+=[4,5,6] list2=list2+[4,5,6] print("inside ",list1,list2) return [snip] # With list1=[1,2,3] list2=[1,2,3] test(list1,list2) print("outside",list1,list2) # I got the following: # inside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] # outside [1, 2, 3, 4, 5, 6] [1, 2, 3] [snip] In this next example, there are two separate lists: list1 = [1,2,3] list2 = [1,2,3] list1 += [4,5,6] print(list1, list2) [1, 2, 3, 4, 5, 6] [1, 2, 3] Does that help? I don't yet understand why in my 2nd example list2 came out as [1, 2, 3] outside. M. K. -- https://mail.python.org/mailman/listinfo/python-list
A strange list concatenation result
def test(list1,list2): list1+=[4,5,6] list2=list2+[4,5,6] print("inside ",list1,list2) return # With list1=list2=[1,2,3] test(list1,list2) print("outside",list1,list2) # I got the following: # inside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6, 4, 5, 6] # outside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] # With list1=[1,2,3] list2=[1,2,3] test(list1,list2) print("outside",list1,list2) # I got the following: # inside [1, 2, 3, 4, 5, 6] [1, 2, 3, 4, 5, 6] # outside [1, 2, 3, 4, 5, 6] [1, 2, 3] -- https://mail.python.org/mailman/listinfo/python-list
ANN: PROVABLEPRIME V.2.0 released
Version 2.0 of PROVABLEPRIME contains an additional application example 3S (sending messages with the signature of the sender). http://s13.zetaboards.com/Crypto/topic/7234475/1/ M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: BASICS v.1.0, a simple encryption scheme
BASICS is a simple encryption scheme (with authentication) based on permutations and dynamic substitutions of characters. In order that the encryption operations involved could be most easily understood by the common users, the scheme highly closely follows the simple and popularly known classical schemes of transposition and substitution but which nonetheless, due to the high dynamics realized via corresponding computer programming means, are strong enough to resist attacks of the adversary with modern analysis resources. The code is available at: http://s13.zetaboards.com/Crypto/topic/7425974/1/ M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: PREFIXCODING 2.0 released
PREFIXCODING Version 2.0, an encryption scheme (with authentication) with pseudo-random prefix codes substitution and pseudo-random transposition, has been released: http://s13.zetaboards.com/Crypto/topic/7164646/1/. The code is to my knowledge currently the single open-source implementation available in any programming language of an idea, due to Motashemi and Wayner, to do encryption with Hufmann coding. Version 2.0 is a complete re-write of Version 1 (not announced in this group), following discussions with the author of a more recent paper treating that idea. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: PROVABLEPRIME 1.1.2 released
PROVABLEPRIME Version 1.1.2, Generation of provable primes with Maurer's algorithm, with illustrative coding of RSA encryption (with authentication) and digital signature for sequences of fixed-sized plaintext blocks and RSA pseudo-random bit generation, has been released: http://s13.zetaboards.com/Crypto/topic/7234475/1/ It is presumably the final polished-up version of PROVABLEPRIME. There is to my knowledge currently no other open-source implementation of Maurer's algorithm in any other popular programming language. The demonstration, that digital signatures can be done with RSA alone, i.e. without additionally employing hashing, appears also to be unique. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: PROVABLEPRIME 1.1.2 released
PROVABLEPRIME Version 1.1.2, Generation of provable primes with Maurer's algorithm, with illustrative coding of RSA encryption (with authentication) and digital signature for sequences of fixed-sized plaintext blocks and RSA pseudo-random bit generation, is available at: http://s13.zetaboards.com/Crypto/topic/7234475/1/ M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
ANN: PREFIXCODING 2.0 released
PREFIXCODING Version 2.0, an encryption scheme (with authentication) with pseudo-random prefix codes substitution and pseudo-random transposition is available at: http://s13.zetaboards.com/Crypto/topic/7164646/1/. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
A syntax question
I don't understand the following phenomenon. Could someone kindly explain it? Thanks in advance. M. K. Shen - count=5 def test(): print(count) if count==5: count+=0 ### Error message if this line is active, otherwise ok. print(count) return test() -- https://mail.python.org/mailman/listinfo/python-list
Log base 2 of large integers
I like to compute log base 2 of a fairly large integer n but with math.log(n,2) I got: OverflowError: long int too large to convert to float. Is there any feasible work-around for that? Thanks in advance. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: newbee
Am 13.08.2014 13:55, schrieb alister: [snip] A related question: How could one write a Python program and have it run on a mobile phone in general (independent of a PC)? M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: Log base 2 of large integers
Am 13.08.2014 15:32, schrieb Steven D'Aprano: Mok-Kong Shen wrote: I like to compute log base 2 of a fairly large integer n but with math.log(n,2) I got: OverflowError: long int too large to convert to float. Is there any feasible work-around for that? If you want the integer log2, that is, the floor of log2, the simplest way is calculate it like this: def log2(n): Return the floor of log2(n). if n = 0: raise ValueError i = -1 while n: n //= 2 i += 1 return i log2(511) = returns 8 log2(512) = returns 9 log2(513) = returns 9 Does that help? That is too inaccurate (e.g. for 513 above) for me, I would like to get accuracy around 0.01 and that for very large n. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: Log base 2 of large integers
Am 13.08.2014 15:16, schrieb Skip Montanaro: http://gnumbers.blogspot.com/2011/10/logarithm-of-large-number-it-is-not.html Might be worth studying for ideas. Thanks. I think the idea may help. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
ANN: SIMPLE 1.1
SIMPLE is a versatile dynamic modern variation of classical encryption scheme with authentication. http://s13.zetaboards.com/Crypto/topic/7201673/1/ As its name implies, it is fairly simple in program logic (and fairly small in code size as well), albeit without compromising any high security requirements that are to be satisfied. For constructive critiques and comments I should be very grateful. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-announce-list Support the Python Software Foundation: http://www.python.org/psf/donations/
Running programs on mobile phones
I have seen by chance a number of years ago a book on Python programming for running on mobile phones (of a certain producer only). What is the current state of the art in that? Could someone kindly give a few good literature references? Thanks in advance. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: MemoryError in data conversion
Am 15.04.2014 01:51, schrieb Gregory Ewing: Mok-Kong Shen wrote: I have yet a question out of curiosity: Why is my 2nd list structure, that apparently is too complex for handling by eval and json, seemingly not a problem for pickle? Pickle is intended for arbitrary data structures, so it is designed to be able to handle deeply-nested and/or recursive data. Eval only has to handle nesting to depths likely to be encountered in source code. Apparently the json parser also assumes you're not going to be using very deep nesting. What I need is to have my (complicated) list to be put into a bytearray, do some proceesing, transfer it to the recipient. The recipient reverses the processing, obtains a bytearray that is the same as my original one and gets from it the same list as mine. Using pickle I can manage to do it (in fact I did try and succeed with my 2nd list), but that's IMHO a rather unnatural/awkward work-around. (It means that I have to pickle out the list to a file and read in the content of the file in order to have it as a bytearray etc. etc.) M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: MemoryError in data conversion
Am 14.04.2014 09:46, schrieb Peter Otten: You ran into a limitation of the compiler. For us to suggest a workaround you'd have to explain why you want to convert the list returned from buildhuffmantree() into python source code and back. That list gives the Huffman encoding tree for compressing a given piece of source text. I am writing a Python code to implement an algorithm (not new, being first sketched in the literature since decades but yet having no publically available implementation as far as I am aware) of encryption processing that has Huffman data compression as its major constituent. Now, for good security against cryptanalysis, this list (which has to be included in the ciphertext for decryption by the recipient) has to be well scrambled in some way. I choose to use 8-bit bytes as units for the scrambling. Hence I convert the list to a bytearray for performing scrambling. On decryption I reverse the scrambling and get back the original bytearray and use ast to recover from it the list so as to be able to do the decompression. Hopefully this description is sufficiently clear. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Re: MemoryError in data conversion
Am 14.04.2014 15:59, schrieb Peter Otten: You could use json, but you may run into the same problem with that, too (only later): import json items = [] for i in range(1000): ... s = json.dumps(items) ... items = [items] ... Traceback (most recent call last): File stdin, line 2, in module File /usr/lib/python3.3/json/__init__.py, line 236, in dumps return _default_encoder.encode(obj) File /usr/lib/python3.3/json/encoder.py, line 191, in encode chunks = self.iterencode(o, _one_shot=True) File /usr/lib/python3.3/json/encoder.py, line 249, in iterencode return _iterencode(o, 0) RuntimeError: maximum recursion depth exceeded while encoding a JSON object i 995 The safest option is probably to serialize the original flist and slist, and use them to create the tree on the fly. Thank you very much for your efforts to help me. I have yet a question out of curiosity: Why is my 2nd list structure, that apparently is too complex for handling by eval and json, seemingly not a problem for pickle? M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
MemoryError in data conversion
The code attached below produces in one of the two IMHO similar cases (excepting the sizes of the lists involved) MemoryError. Could experts kindly tell why that's so and whether there is any work-around feasible. Thanks in advances. M. K. Shen - import ast def buildhuffmantree(slist,flist): item=slist[:] freq=flist[:] while len(item)2: mn=min(freq) id=freq.index(mn) u=item[id] del item[id] del freq[id] mn1=min(freq) id=freq.index(mn1) v=item[id] del item[id] del freq[id] item.append([u,v]) freq.append(mn+mn1) return(item) def processing(slist,flist): bintree=buildhuffmantree(slist,flist) print(bintree) byarray=bytearray(str(bintree),latin-1) bintree1=ast.literal_eval(byarray.decode(latin-1)) print(bintree1) print(bintree==bintree1) slist1=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 'eof'] flist1=[18, 16, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, -1] slist2=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 'eof'] flist2=[2, 2, 0, 2, 0, 0, 1, 2, 1, 0, 2, 0, 0, 1, 1, 0, 2, 0, 0, 0, 1, 0, 0, 0, 2, 0, 0, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 2, 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1] processing(slist1,flist1) ### This works fine print() processing(slist2,flist2) ### This leads to MemoryError -- https://mail.python.org/mailman/listinfo/python-list
A data conversion question
A newbie's question of curiosity: If I have g=[1,[2]] and bg=bytearray(str(g),latin-1) could I somehow get back from bg a list g1 that is the same as g? Thanks in advance. M. K. Shen -- https://mail.python.org/mailman/listinfo/python-list
Ordering in the printout of a dictionary
Could someone kindly explain a phenomenon in the following where: (1) I first typed in a dictionary but got a printout in a reordered form. (2) I then typed in the reordered form but got a printout in the order that I typed in originally in (1). That is, there is no stable standard ordering. Why is that so? Is there a way to force a certain ordering of the printout or else somehow manage to get at least a certain stable ordering of the printout (i.e. input and output are identical)? Thanks in advance. M. K. Shen -- {'label': 3, 'parent': 0, 'left child': 1, 'right child': 2} {'right child': 2, 'parent': 0, 'left child': 1, 'label': 3} {'right child': 2, 'parent': 0, 'left child': 1, 'label': 3} {'label': 3, 'parent': 0, 'left child': 1, 'right child': 2} -- https://mail.python.org/mailman/listinfo/python-list
Running programs on mobile phones
Could one write Python codes and have them run on one's own mobile phone? If yes, are there some good literatures? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: Output from to_bytes
Am 28.05.2013 17:35, schrieb Grant Edwards: On 2013-05-26, Mok-Kong Shen mok-kong.s...@t-online.de wrote: I don't understand why with the code: for k in range(8,12,1): print(k.to_bytes(2,byteorder='big')) one gets the following output: b'\x00\x08' b'\x00\t' b'\x00\n' b'\x00\x0b' I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'. Anyway, how could I get the output in the forms I want? Well, it would help if you told us what output form you want. As I stated, I like the 2nd and 3rd be b'\x00\x09' and b'\x00\x0a' respectively. This is what would expeacted to be in a hexadecimal notation IMHO in other PLs. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get an integer from a sequence of bytes
Am 30.05.2013 21:22, schrieb Ned Batchelder: On 5/30/2013 2:26 PM, Mok-Kong Shen wrote: Am 27.05.2013 17:30, schrieb Ned Batchelder: On 5/27/2013 10:45 AM, Mok-Kong Shen wrote: From an int one can use to_bytes to get its individual bytes, but how can one reconstruct the int from the sequence of bytes? The next thing in the docs after int.to_bytes is int.from_bytes: http://docs.python.org/3.3/library/stdtypes.html#int.from_bytes I am sorry to have overlooked that. But one thing I yet wonder is why there is no direct possibilty of converting a byte to an int in [0,255], i.e. with a constrct int(b), where b is a byte. Presumably you want this to work: int(b'\x03') 3 But you also want this to work: int(b'7') 7 These two interpretations are incompatible. If b'\x03' becomes 3, then shouldn't b'\x37' become 55? But b'\x37' is b'7', and you want that to be 7. b'7' is the byte with the character 7 in a certain code, so that's ok. In other PLs one assigns an int to a byte, with that int in either decimal notation or hexadecimal notation, or else one assigns a character to it, in which case it gets the value of the character in a certain code. What I don't yet understand is why Python is apprently different from other PLs in that point in not allowing direct coersion of a byte to an int. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: How to get an integer from a sequence of bytes
Am 27.05.2013 17:30, schrieb Ned Batchelder: On 5/27/2013 10:45 AM, Mok-Kong Shen wrote: From an int one can use to_bytes to get its individual bytes, but how can one reconstruct the int from the sequence of bytes? The next thing in the docs after int.to_bytes is int.from_bytes: http://docs.python.org/3.3/library/stdtypes.html#int.from_bytes I am sorry to have overlooked that. But one thing I yet wonder is why there is no direct possibilty of converting a byte to an int in [0,255], i.e. with a constrct int(b), where b is a byte. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
How to get an integer from a sequence of bytes
From an int one can use to_bytes to get its individual bytes, but how can one reconstruct the int from the sequence of bytes? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Output from to_bytes
I don't understand why with the code: for k in range(8,12,1): print(k.to_bytes(2,byteorder='big')) one gets the following output: b'\x00\x08' b'\x00\t' b'\x00\n' b'\x00\x0b' I mean the 2nd and 3rd should be b'\x00\x09' and b'x00\x0a'. Anyway, how could I get the output in the forms I want? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Symbolic computations
I heard of names of two systems for Python users to do symbolic computations: SymPy and Sage. Could someone say a few lines from experiences about their comparisons? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
[newbie] A question about lists and strings
In an earlier question about lists, I was told about the issue of creation of local names in a function. However, I still can't understand why the program below outputs: [999] sss [999] and not two identical lines of output. For both operators += should anyway work in similar manner in the function xx in my view. Thanks for your help in advance. M. K. Shen -- def xx(list,str): list+=[999] str+=sss lista=[] stra= lista+=[999] stra+=sss print(lista,stra) listb=[] strb= xx(listb,strb) print(listb,strb) -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] A question about lists and strings
Am 10.08.2012 11:48, schrieb Roman Vashkevich: [snip] The function It takes list by reference and creates a new local str. When it's called with listb and strb arguments, listb is passed by reference and mutated. A string sss is concatenated with an empty local str. Nothing more happens. Since local str is not returned by xx(), it can not be expected to be printed out in the statement that follows. What is printed out in the print statement is the mutated listb and the global strb. Thanks for the explanation of the output obtained. But this means nonetheless that parameters of types lists and strings are dealt with in inherently (semantically) different ways by Python, right? M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] A question about lists and strings
Am 10.08.2012 12:07, schrieb Dave Angel: [snip] At this point, in top-level code, the listb object has been modified, and the strb one has not; it still is bound to the old value. This means there is no way of modifying a string at the top level via a function, excepting through returning a new value and assigning that to the string name at the top level. Please again correct me, if I am wrong. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] A question about lists and strings
Am 10.08.2012 12:40, schrieb Chris Angelico: But it's probably worth thinking about exactly why you're wanting to change that string, and what you're really looking to accomplish. There may well be a better way. My problem is the following: I have at top level 3 lists and 3 strings: lista, listb, listc and stra, strb, strc. I can with a single function call change all 3 list values. How could I realize similar changes of the 3 string values with a single function call? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] A question about lists and strings
Am 10.08.2012 12:56, schrieb Roman Vashkevich: I am not sure I understand your question. Can you rephrase it or make it more explicit? I have just detailed my problem and Dave Angel has shown how to solve it properly. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
A difficulty with lists
I ran the following code: def xx(nlist): print(begin: ,nlist) nlist+=[999] print(middle:,nlist) nlist=nlist[:-1] print(final: ,nlist) u=[1,2,3,4] print(u) xx(u) print(u) and obtained the following result: [1, 2, 3, 4] begin: [1, 2, 3, 4] middle: [1, 2, 3, 4, 999] final: [1, 2, 3, 4] [1, 2, 3, 4, 999] As beginner I couldn't understand why the last line wasn't [1, 2, 3, 4]. Could someone kindly help? M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
[newbie] String to binary conversion
If I have a string abcd then, with 8-bit encoding of each character, there is a corresponding 32-bit binary integer. How could I best obtain that integer and from that integer backwards again obtain the original string? Thanks in advance. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list
Re: [newbie] String to binary conversion
Am 06.08.2012 22:59, schrieb Tobiah: The binascii module looks like it might have something for you. I've never used it. Thanks for the hint, but if I don't err, the module binascii doesn't seem to work. I typed: import binascii and a line that's given as example in the document: crc = binascii.crc32(hello) but got the following error message: TypeError: 'str' does not support the buffer interface. The same error message appeared when I tried the other functions. M. K. Shen -- http://mail.python.org/mailman/listinfo/python-list