Re: [Tutor] recursivity and lists

2016-03-05 Thread Mark Lawrence
On 05/03/2016 18:46, Danny Yoo wrote: On Mar 5, 2016 5:56 AM, "Robert Nanney" wrote: Would this meet the requirements? It's doing a sort, but not in a merging way. Merge sort takes advantage of a property of the input lists: the input lists are known to be already sorted. The general sort

Re: [Tutor] recursivity and lists

2016-03-05 Thread Mark Lawrence
On 04/03/2016 19:25, sina sareth via Tutor wrote: Hi ThereI have those projects and I would like to get some directions the way to tackle them. Thanks 1) XML parsing into database. 2) Do the same thing but this time, get ALL the quotes and save them as separate database entries (you will have

Re: [Tutor] recursivity and lists

2016-03-05 Thread Danny Yoo
On Mar 5, 2016 5:56 AM, "Robert Nanney" wrote: > > Would this meet the requirements? It's doing a sort, but not in a merging way. Merge sort takes advantage of a property of the input lists: the input lists are known to be already sorted. The general sort routine for lists doesn't take much adv

Re: [Tutor] recursivity and lists

2016-03-05 Thread Robert Nanney
Would this meet the requirements? merged_list = list1.extend(list2).sort() On Mar 4, 2016 3:34 PM, "Danny Yoo" wrote: > > As we can see, we have to do a lot more consideration of what state > > our values are in, due to all the mutation happening. It also shows > > that the second recursive cal

Re: [Tutor] recursivity and lists

2016-03-04 Thread sina sareth via Tutor
Hi ThereI have those projects and I would like to get some directions the way to tackle them. Thanks 1)  XML parsing into database.  2) Do the same thing but this time, get ALL the quotes and save them as separate database entries (you will have to do a for loop for this).  3) Use Django to build

Re: [Tutor] recursivity and lists

2016-03-04 Thread Danny Yoo
> As we can see, we have to do a lot more consideration of what state > our values are in, due to all the mutation happening. It also shows > that the second recursive call to the linear_merge() is not really > using it to merge: it's really trying to select the list that was used > to accumulate

Re: [Tutor] recursivity and lists

2016-03-04 Thread Danny Yoo
> Both work but I am not satisfied. Is there not a method that could do the job > of '+' operator (namely concatenate in a copy)? > No; unfortunately Python doesn't make functional approaches as convenient as I would personally like. The copy operation on lists itself is expensive to do, so tha

Re: [Tutor] recursivity and lists

2016-03-04 Thread Alan Gauld
On 04/03/16 19:25, sina sareth wrote: > Hi There Hi, welcome to tutor. But please do not hijack an existing thread for a new topic. Post a new message to tutor@python.org. Otherwise the archive gets very confusing for people searching for answers. Or even for people using threaded email/news read

Re: [Tutor] recursivity and lists

2016-03-04 Thread Alan Gauld
On 04/03/16 15:00, Gaston wrote: > Both work but I am not satisfied. Is there not a method that could do > the job of '+' operator (namely concatenate in a copy)? Why would you want a method? An operator is a perfectly legitimate feature and is at least as readable as a method. It is certainly n

Re: [Tutor] recursivity and lists

2016-03-04 Thread Gaston
Thank you for these comments. Made me realize that I do not fully understand my code, and need to think about it a bit more. I totally understand the huge side effects, and it is true that it would be dangerous if the function was to actually be used. I would like to find a fully functional ve

Re: [Tutor] recursivity and lists

2016-03-03 Thread Danny Yoo
Some code comments: The solution you have depends very much on mutation and side effects: I recommend you try to stay as functional as you can in this situation. By mixing mutation into the solution, there are certain things that the program is doing that isn't part of the traditional behavior of

Re: [Tutor] recursivity and lists

2016-03-02 Thread Gaston
Thanks a lot for your help. This was the problem. I fixed it this way : def linear_merge(list1, list2): if list1==[]: return list2 elif list2==[]: return list1 elif list1[-1]>list2[-1]: a=list1.pop() linear_merge(list1,list2).append(a) return linear_merge(list1,list2) else:

Re: [Tutor] recursivity and lists

2016-03-01 Thread Danny Yoo
Also, as a quick note: Python list append is not functional: it mutates rather than returns a useful return value. You may need to revisit the parts in the code where it assumes a different behavior from functional append. On Mar 1, 2016 12:36 PM, "Danny Yoo" wrote: > > > > > Problem is that pyt

Re: [Tutor] recursivity and lists

2016-03-01 Thread Danny Yoo
> > Problem is that python complains that he cannot know the type of the result of this function (list). In C++ I would specify the type, but from what I understood, Python should not need this. What did I miss ? Can you copy the exact stack trace of the error? It'll help: you've interpreted what

[Tutor] recursivity and lists

2016-03-01 Thread Gaston
Hello everyone ! I was trying to do this little exercise: # E. Given two lists sorted in increasing order, create and return a merged # list of all the elements in sorted order. You may modify the passed in lists. # Ideally, the solution should work in "linear" time, making a single # pass of b