Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Rafael Knuth
Hej there, I don't know if everyone would consider this more elegant but it's certainly shorter: Thanks! def DigitSum(YourNumber): ... return sum(map(int, YourNumber)) ... DigitSum('55') 10 I don't understand yet what the map function does - can you explain? I read the Python 3.3.0

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-10 Thread Jignesh Sutar
Thanks Steve, Alan. Sound advice. Very much a novice so trying to pick up good habits. Will definitely take on board your comments! Thanks again. Jignesh On 10 December 2013 00:46, Alan Gauld alan.ga...@btinternet.com wrote: On 09/12/13 23:46, Steven D'Aprano wrote: Python has two different

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Oscar Benjamin
On 10 December 2013 09:39, Rafael Knuth rafael.kn...@gmail.com wrote: def DigitSum(YourNumber): ... return sum(map(int, YourNumber)) ... DigitSum('55') 10 I don't understand yet what the map function does - can you explain? I read the Python 3.3.0 documentation on that topic but I

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Steven D'Aprano
On Tue, Dec 10, 2013 at 10:39:34AM +0100, Rafael Knuth wrote: I don't understand yet what the map function does - can you explain? I read the Python 3.3.0 documentation on that topic but I frankly didn't really understand it The map function comes from so-called functional programming

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Asokan Pichai
On Tue, Dec 10, 2013 at 3:09 PM, Rafael Knuth rafael.kn...@gmail.comwrote: Hej there, I don't know if everyone would consider this more elegant but it's certainly shorter: Thanks! def DigitSum(YourNumber): ... return sum(map(int, YourNumber)) ... DigitSum('55') 10 I don't

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Asokan Pichai
On Tue, Dec 10, 2013 at 4:06 PM, Asokan Pichai paso...@talentsprint.comwrote: On Tue, Dec 10, 2013 at 3:09 PM, Rafael Knuth rafael.kn...@gmail.comwrote: Hej there, I don't know if everyone would consider this more elegant but it's certainly shorter: Thanks! def

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Steven D'Aprano
On Tue, Dec 10, 2013 at 10:39:34AM +0100, Rafael Knuth wrote: def DigSum (integer): s = 0 while integer != 0: integer, remainder = divmod(integer, 10) s += remainder print(s) A thought comes to mind... an very important lesson is to learn the difference between

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Wolfgang Maier
Asokan Pichai pasokan at talentsprint.com writes: If you liked it, I will give you one that uses one less variable def digitSum(n):       dsum = 0       while n 0:             dsum += n % 10             n /= 10       return dsum Stupid of me not to have mentioned that this Python

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 11:56 AM, Steven D'Aprano wrote: This is because the function does *two things*, when it should do one. First it calculates the digit sum, and then it prints it. print's inside functions are a sign of debug not completely cleaned ;-) (and also a sign that test funcs do not

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Wolfgang Maier
Steven D'Aprano steve at pearwood.info writes: On Tue, Dec 10, 2013 at 10:39:34AM +0100, Rafael Knuth wrote: def DigSum (integer): s = 0 while integer != 0: integer, remainder = divmod(integer, 10) s += remainder print(s) A thought comes to mind...

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-10 Thread spir
On 12/10/2013 12:46 AM, Steven D'Aprano wrote: In Python 2.7, you can abbreviate that last one slightly: '{} {}'.format(number, word) Why 2.7? By me also works with 3.3. Either should be preferred to building the string by hand with + signs. The rule of thumb I use is to say that adding two

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
[off-topic] On 12/10/2013 01:39 PM, Wolfgang Maier wrote: def digits(n): Generator that breaks down an integer into digits from right to left. while n0: yield n % 10 n //= 10 Aha! one more sign that we write numbers backwards! Denis

Re: [Tutor] Writing to CSV string containing quote and comma

2013-12-10 Thread Steven D'Aprano
On Tue, Dec 10, 2013 at 01:43:57PM +0100, spir wrote: On 12/10/2013 12:46 AM, Steven D'Aprano wrote: In Python 2.7, you can abbreviate that last one slightly: '{} {}'.format(number, word) Why 2.7? By me also works with 3.3. Sorry, I meant Python 2.7 or later. -- Steven

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Rafael Knuth
Hej Steven, thanks for the clarification. I have two questions - one about map function and the other about return. So, in mathematics we might have a mapping between (let's say) counting numbers 1, 2, 3, 4, ... and the even numbers larger than fifty, 52, 54, 56, ... and so on. The mapping

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Steven D'Aprano
On Tue, Dec 10, 2013 at 02:31:55PM +0100, Rafael Knuth wrote: So in Python, we can do this with map. First we define a function to do the transformation, then pass it to map: def transform(n): return 50 + 2*n Notice here that transformation function takes *one* value, and

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 02:31 PM, Rafael Knuth wrote: Hej Steven, thanks for the clarification. I have two questions - one about map function and the other about return. So, in mathematics we might have a mapping between (let's say) counting numbers 1, 2, 3, 4, ... and the even numbers larger than

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread spir
On 12/10/2013 02:31 PM, Rafael Knuth wrote: Hej Steven, thanks for the clarification. I have two questions - one about map function and the other about return. So, in mathematics we might have a mapping between (let's say) counting numbers 1, 2, 3, 4, ... and the even numbers larger than

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread Mark Lawrence
On 10/12/2013 18:08, spir wrote: There is another standard tool called 'apply' in general, which sequentially *performms* the effect of an action on a sequence of inputs. The apply function has been deprecated since 2.3 and never got into Python 3. -- My fellow Pythonistas, ask not what

Re: [Tutor] Converting integers into digit sum (Python 3.3.0)

2013-12-10 Thread eryksun
On Tue, Dec 10, 2013 at 1:08 PM, spir denis.s...@gmail.com wrote: There is another standard tool called 'apply' in general, which sequentially *performms* the effect of an action on a sequence of inputs. Since it just applies action, 'apply' does not return any result. 'apply' is rarely used

[Tutor] Subprocess communications query

2013-12-10 Thread Reuben
Hi, There exists two Linux machines A and B. Machine B contains python script which needs to be run e.g. Test.py In order to run that script, machine A needs to telnet into machine B and then execute python Test.py How can this be implemented? Is subprocess library to be used?if yes, an example

Re: [Tutor] Subprocess communications query

2013-12-10 Thread Danny Yoo
On Tue, Dec 10, 2013 at 11:28 AM, Reuben reuben.dl...@gmail.com wrote: Hi, There exists two Linux machines A and B. Machine B contains python script which needs to be run e.g. Test.py In order to run that script, machine A needs to telnet into machine B and then execute python Test.py

Re: [Tutor] Subprocess communications query

2013-12-10 Thread Reuben
I want to implement a python script on machine A to do telnet/ssh into machine B (this might be easy)and then run the Test.py (this is challenging) On 11-Dec-2013 1:05 AM, Danny Yoo d...@hashcollision.org wrote: On Tue, Dec 10, 2013 at 11:28 AM, Reuben reuben.dl...@gmail.com wrote: Hi,

Re: [Tutor] Subprocess communications query

2013-12-10 Thread Danny Yoo
Ok; so in your situation, it sounds like machine A is also running a Python script, and you want to automate the remote administration of machine B through that program. If that's the case, you may want to look at the Fabric library, or other libraries that help with driving ssh through Python:

Re: [Tutor] Subprocess communications query

2013-12-10 Thread Steve Willoughby
Reuben reuben.dl...@gmail.com wrote: I want to implement a python script on machine A to do telnet/ssh into machine B (this might be easy)and then run the Test.py (this is challenging) On 11-Dec-2013 1:05 AM, Danny Yoo d...@hashcollision.org wrote: On Tue, Dec 10, 2013 at 11:28 AM, Reuben

Re: [Tutor] Subprocess communications query

2013-12-10 Thread Steven D'Aprano
On Wed, Dec 11, 2013 at 12:58:16AM +0530, Reuben wrote: Hi, There exists two Linux machines A and B. Machine B contains python script which needs to be run e.g. Test.py In order to run that script, machine A needs to telnet into machine B and then execute python Test.py Using telnet is

[Tutor] Need to create code

2013-12-10 Thread Matthew Thomas
Write a function named SSN2Name with an interactive loop. The function takes the dictionary named data as input argument where this dictionary stores the key, value pairs of SSN, name of person. The SSN is in the string format 'xxx-xx-' and name is also a string. Each iteration of the

[Tutor] recursive function example

2013-12-10 Thread ugajin
I am looking at a simple recursive function, and oxymoron aside, I am having difficulty in seeing what occurs. I have tried adding some debug print commands to help break the thing down. This helps a lot, but I still have a question that I need help with. Here is original code: def mult(a, b):

Re: [Tutor] Need to create code

2013-12-10 Thread Alan Gauld
On 10/12/13 15:45, Matthew Thomas wrote: Write a function named *SSN2Name* with an interactive loop. This is obviously some kind of homework exercise. We do not do your homework for you but we will give you pointers or clarify issues if you get stuck. But we expect you to make a start, post

Re: [Tutor] recursive function example

2013-12-10 Thread Alan Gauld
On 10/12/13 14:48, uga...@talktalk.net wrote: Here is original code: def mult(a, b): if b == 0: return 0 rest = mult(a, b - 1) value = a + rest return value print 3 * 2 = , mult(3, 2) I see how python outputs the string mult(3,2) before running the function, No

Re: [Tutor] Need to create code

2013-12-10 Thread Mark Lawrence
On 10/12/2013 15:45, Matthew Thomas wrote: Write a function named *SSN2Name* with an interactive loop. The function takes the dictionary named*data*as input argument where this dictionary stores the key, value pairs of SSN, name of person. The SSN is in the string format 'xxx-xx-' and name

Re: [Tutor] Need to create code

2013-12-10 Thread Danny Yoo
Hi Thomas, In order to use mailing list like Python-tutor effectively, you'll probably want to read: http://www.catb.org/~esr/faqs/smart-questions.html In particular, pay special attention to: http://www.catb.org/~esr/faqs/smart-questions.html#homework You're basically violating the