Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Alan Gauld
On 04/08/12 20:44, Alonzo Quijote wrote: There must be a good reason that the responders use a tmp variable like this? But I notice that the same effects can be obtained with: def setValueAtPosition2(list, pos, value): for i in pos[:-1]: list = list[i] list[pos[-1]] = valu

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Alonzo Quijote
Thanks for all the help with this. I have 2 very quick follow-up questions: --- 1. Several responses proposed code like this: def setValueAtPosition(list, pos, value): tmp = list for i in pos[:-1]: tmp = tmp[i] tmp[pos[-1]] = value There must be a good reason that the responders u

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Asokan Pichai
On Sat, Aug 4, 2012 at 12:28 PM, Alonzo Quijote wrote: > Is there a way to define a function which takes >a list (of lists), >a position specified by a list of integers [i0,i1,...,in], and >a value > and returns the result of setting > list[i0][i1]...[in]=value > > The following fu

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Peter Otten
Alonzo Quijote wrote: > Is there a way to define a function which takes >a list (of lists), >a position specified by a list of integers [i0,i1,...,in], and >a value > and returns the result of setting > list[i0][i1]...[in]=value > > The following function works for positions up to

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Steven D'Aprano
On 04/08/12 16:58, Alonzo Quijote wrote: Is there a way to define a function which takes a list (of lists), a position specified by a list of integers [i0,i1,...,in], and a value and returns the result of setting list[i0][i1]...[in]=value Yes it is possible, but if you need th

Re: [Tutor] Recursive assignment in nested lists

2012-08-04 Thread Puneeth Chaganti
On Sat, Aug 4, 2012 at 12:28 PM, Alonzo Quijote wrote: > Is there a way to define a function which takes >a list (of lists), >a position specified by a list of integers [i0,i1,...,in], and >a value > and returns the result of setting > list[i0][i1]...[in]=value > > The following fu

[Tutor] Recursive assignment in nested lists

2012-08-04 Thread Alonzo Quijote
Is there a way to define a function which takes a list (of lists), a position specified by a list of integers [i0,i1,...,in], and a value and returns the result of setting list[i0][i1]...[in]=value The following function works for positions up to length 3 only. Is it possible to writ