Re: [Tutor] Mutable data type in python

2015-10-06 Thread Oscar Benjamin
On 4 October 2015 at 00:13, Alan Gauld wrote: > On 03/10/15 23:20, C Smith wrote: >> >> On Sat, Oct 3, 2015 at 11:55 AM, Alan Gauld >> wrote: >>> >>> On 03/10/15 19:10, C Smith wrote: > > Here is my modified version which I think works as you want: > > def findMinDepthPath(n): >>>

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Alan Gauld
On 03/10/15 23:20, C Smith wrote: On Sat, Oct 3, 2015 at 11:55 AM, Alan Gauld wrote: On 03/10/15 19:10, C Smith wrote: Here is my modified version which I think works as you want: def findMinDepthPath(n): if n <= 0: raise ValueError elif n==1: return 0 elif n==2 or

Re: [Tutor] Mutable data type in python

2015-10-03 Thread C Smith
On Sat, Oct 3, 2015 at 11:55 AM, Alan Gauld wrote: > On 03/10/15 19:10, C Smith wrote: >>> >>> Here is my modified version which I think works as you want: >>> >>> def findMinDepthPath(n): >>> if n <= 0: raise ValueError >>> elif n==1: >>> return 0 >>> elif n==2 or n==3: >>

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Alan Gauld
On 03/10/15 19:10, C Smith wrote: Here is my modified version which I think works as you want: def findMinDepthPath(n): if n <= 0: raise ValueError elif n==1: return 0 elif n==2 or n==3: return 1 else: d1 = findMinDepthPath(n-1)+1 d2 = d3 =

Re: [Tutor] Mutable data type in python

2015-10-03 Thread C Smith
> Here is my modified version which I think works as you want: > > def findMinDepthPath(n): > if n <= 0: raise ValueError > elif n==1: > return 0 > elif n==2 or n==3: > return 1 > else: > d1 = findMinDepthPath(n-1)+1 > d2 = d3 = (d1+1) # initialize to

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Laura Creighton
One thing you can do is to make your variable live in another module. This is a common way to make config files, for instance. say you have a file called config.py which contains the single line my_int = 0 then in your main program you can do: import config and start using config.my_int wherev

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Alan Gauld
On 03/10/15 09:23, Anshu Kumar wrote: Hi Alan, I have given a wrong example of 16 . I am sorry for it. You are correct it will take only 4 turns. If i consider your solution for number 10 it will go like this 10-->10/2 =5 --> 5-1=4--> 4/2 =2-->2/2 =1 which gives 4 as output but answer would

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Anshu Kumar
Hi Alan, I have given a wrong example of 16 . I am sorry for it. You are correct it will take only 4 turns. If i consider your solution for number 10 it will go like this 10-->10/2 =5 --> 5-1=4--> 4/2 =2-->2/2 =1 which gives 4 as output but answer would be in 3 steps 10-->10-1=9-->9/3=3-->3/3=1

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Laura Creighton
>it works fine with global variable or a list type parameter for depth but i >am looking for a way where i would be able to use a parameter which will be >shared across all invocation and it should certainly not be a list coz i >don't need a list > >Thanks and appreciate your help, >Anshu I am not

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Alan Gauld
On 03/10/15 03:46, Anshu Kumar wrote: Hi Alan, I was trying to solve a simple dynamic programming problem. It goes like this. I have an input integer and i can choose to divide it by two or three or subtract by one to reduce it to one. there is a condition the number has to be divisible by 2 or

Re: [Tutor] Mutable data type in python

2015-10-03 Thread Anshu Kumar
Hi Alan, I was trying to solve a simple dynamic programming problem. It goes like this. I have an input integer and i can choose to divide it by two or three or subtract by one to reduce it to one. there is a condition the number has to be divisible by 2 or 3 if we are dividing by two or three re

Re: [Tutor] Mutable data type in python

2015-10-02 Thread Cameron Simpson
On 02Oct2015 22:22, Anshu Kumar wrote: When we invoke the same function inside a function (recursive function), i want to keep track of some data across all function invocation so i should have shareable type but built in data types string, int are not helping as they are immutable they are chan

Re: [Tutor] Mutable data type in python

2015-10-02 Thread Alan Gauld
On 02/10/15 17:52, Anshu Kumar wrote: When we invoke the same function inside a function (recursive function), i want to keep track of some data across all function invocation so i should have shareable type but built in data types string, int are not helping as they are immutable they are chang

[Tutor] Mutable data type in python

2015-10-02 Thread Anshu Kumar
Hi Everyone, I have been facing this problem from a while in python could I please be helped? When we invoke the same function inside a function (recursive function), i want to keep track of some data across all function invocation so i should have shareable type but built in data types string, i