Re: [Tutor] Unexpected result of division by negative integer, was: (no subject)

2012-06-02 Thread Peter Otten
Jason Barrett wrote: [Jason, please use "reply all" instead of sending a private mail. Your answer will then appear on the mailing list and other readers get a chance to offer an alternative explanation.] >> In python, why does 17/-10= -2? Shouldn't it be -1? > >> http://docs.python.org/faq/pr

[Tutor] Octal confusion, please explain why. Python 3.2

2012-06-02 Thread Jordan
Hello, first off I am using Python 3.2 on Linux Mint 12 64-bit. I am confused as to why I can not successfully compare a variable that was created as an octal to a variable that is converted to an octal in a if statement yet print yields that they are the same octal value. I think it is because the

Re: [Tutor] Joining all strings in stringList into one string

2012-06-02 Thread Jordan
On 05/30/2012 06:21 PM, Akeria Timothy wrote: > Hello all, > > I am working on learning Python(on my own) and ran into an exercise > that I figured out but I wanted to know if there was a different way > to write the code? I know he wanted a different answer for the body > because we haven't gott

Re: [Tutor] Unexpected result of division by negative integer, was: (no subject)

2012-06-02 Thread Alan Gauld
On 02/06/12 09:52, Peter Otten wrote: I just started programming so all this is new to me. I don't really understand the explanation. I'm a novice at programming. OK, Here is an attempt to explain the explanation! Original question: Why does -17 / 10 => -2 instead of -1 Python FAQ response:

Re: [Tutor] Octal confusion, please explain why. Python 3.2

2012-06-02 Thread Steven D'Aprano
Jordan wrote: Hello, first off I am using Python 3.2 on Linux Mint 12 64-bit. I am confused as to why I can not successfully compare a variable that was created as an octal to a variable that is converted to an octal in a if statement yet print yields that they are the same octal value. Because

Re: [Tutor] Octal confusion, please explain why. Python 3.2

2012-06-02 Thread Jordan
Thank you for the detailed answer, now I understand and I understand that each number format is an integer just with a different base and cosmetic appearance. On 06/02/2012 01:51 PM, Steven D'Aprano wrote: > Jordan wrote: >> Hello, first off I am using Python 3.2 on Linux Mint 12 64-bit. >> I am c

Re: [Tutor] Octal confusion, please explain why. Python 3.2

2012-06-02 Thread Alan Gauld
On 02/06/12 12:29, Jordan wrote: think it is because they are transported around within python as a integer value, is this correct and if so why? Steven has already answered your issue but just to emphasise this point. Python stores all data as binary values in memory. Octal, decimal, hex are

Re: [Tutor] Division by negative numbers [was: no subject]

2012-06-02 Thread Steven D'Aprano
Jason Barrett wrote: In python, why does 17/-10= -2? Shouldn't it be -1? Integer division with negative numbers can be done in two different ways. (1) 17/-10 gives -1, with remainder 7. Proof: -1 times -10 is 10, plus 7 gives 17. (2) 17/-10 gives -2, with remainder -3. Proof: -2 times -10

Re: [Tutor] Joining all strings in stringList into one string

2012-06-02 Thread Steven D'Aprano
Jordan wrote: #Another version might look like this: def join_strings2(string_list): final_string = '' for string in string_list: final_string += string print(final_string) return final_string Please don't do that. This risks becoming slow. REALLY slow. Painfully slow.

[Tutor] How to identify clusters of similar files

2012-06-02 Thread Albert-Jan Roskam
Hi, I want to use difflib to compare a lot (tens of thousands) of text files. I know that many files are quite similar as they are subsequent versions of the same document (a primitive kind of version control). What would be a good approach to cluster the files based on their likeness? I want t

Re: [Tutor] Joining all strings in stringList into one string

2012-06-02 Thread Jordan
Thanks for the excellent feedback and very informative. I guess I just did not consider the memory side of things and did not think about just how much extra addition was having to occur. Additionally I also found this supporting link: http://wiki.python.org/moin/PythonSpeed/PerformanceTips#String_

Re: [Tutor] How to identify clusters of similar files

2012-06-02 Thread Steven D'Aprano
Albert-Jan Roskam wrote: Hi, I want to use difflib to compare a lot (tens of thousands) of text files. I know that many files are quite similar as they are subsequent versions of the same document (a primitive kind of version control). What would be a good approach to cluster the files based on