[Tutor] recursive problem

2010-09-09 Thread Roelof Wobben
Hello, I have this : def recursive_count(target, nested_num_list): """ >>> recursive_count(2, [2, 9, [2, 1, 13, 2], 8, [2, 6]]) 4 >>> recursive_count(7, [[9, [7, 1, 13, 2], 8], [7, 6]]) 2 >>> recursive_count(15, [[9, [7, 1, 13, 2], 8], [2, 6]]) 0

Re: [Tutor] recursive problem

2010-09-09 Thread Shashwat Anand
On Thu, Sep 9, 2010 at 2:21 PM, Roelof Wobben wrote: > Hello, > > I have this : > > def recursive_count(target, nested_num_list): > """ > >>> recursive_count(2, [2, 9, [2, 1, 13, 2], 8, [2, 6]]) > 4 > >>> recursive_count(7, [[9, [7, 1, 13, 2], 8], [7, 6]]) > 2 >

Re: [Tutor] recursive problem

2010-09-09 Thread Roelof Wobben
From: anand.shash...@gmail.com Date: Thu, 9 Sep 2010 15:08:10 +0530 Subject: Re: [Tutor] recursive problem To: rwob...@hotmail.com CC: tutor@python.org On Thu, Sep 9, 2010 at 2:21 PM, Roelof Wobben wrote: Hello, I have this : def recursive_count(target, nested_num_list): """

Re: [Tutor] recursive problem

2010-09-09 Thread Shashwat Anand
On Thu, Sep 9, 2010 at 3:11 PM, Roelof Wobben wrote: > > > -- > From: anand.shash...@gmail.com > Date: Thu, 9 Sep 2010 15:08:10 +0530 > Subject: Re: [Tutor] recursive problem > To: rwob...@hotmail.com > CC: tutor@python.org > > > > On Thu, Sep 9, 2010 at 2:21 PM, Roelo

Re: [Tutor] recursive problem

2010-09-09 Thread Walter Prins
On 9 September 2010 12:59, Shashwat Anand wrote: > > Let's say n, l = 2, [2, 9, [2, 1, 13, 2], 8, [2, 6]] > Simply Flatten the list l, which will be then be; flatten(l) = [ 2, [2, 9, > 2, 1,13, 2, 8, 2, 6 ] > Now count for n; flatten.count(n) > > This is fine except that the excercise probably ha

Re: [Tutor] recursive problem

2010-09-09 Thread Joel Goldstick
On Thu, Sep 9, 2010 at 7:59 AM, Shashwat Anand wrote: > > > On Thu, Sep 9, 2010 at 3:11 PM, Roelof Wobben wrote: > >> >> >> -- >> From: anand.shash...@gmail.com >> Date: Thu, 9 Sep 2010 15:08:10 +0530 >> Subject: Re: [Tutor] recursive problem >> To: rwob...@hotmail.com

Re: [Tutor] recursive problem

2010-09-09 Thread Luke Paireepinart
Shouldn't there be a way to do this without type checking? Duck typing! Sent from my iPhone On Sep 9, 2010, at 7:33 AM, Joel Goldstick wrote: > > > On Thu, Sep 9, 2010 at 7:59 AM, Shashwat Anand > wrote: > > > On Thu, Sep 9, 2010 at 3:11 PM, Roelof Wobben wrote: > > > From: anand.shas

Re: [Tutor] recursive problem

2010-09-09 Thread Joel Goldstick
On Thu, Sep 9, 2010 at 10:26 AM, Luke Paireepinart wrote: > Shouldn't there be a way to do this without type checking? Duck typing! > > Your post got me thinking. Maybe better to test if the object can return an iter method. If it throws an error, then look at its value. If it doesn't, then its

Re: [Tutor] recursive problem

2010-09-09 Thread Francesco Loffredo
On 09/09/2010 17.05, Joel Goldstick wrote: On Thu, Sep 9, 2010 at 10:26 AM, Luke Paireepinart mailto:rabidpoob...@gmail.com>> wrote: Shouldn't there be a way to do this without type checking? Duck typing! Your post got me thinking. Maybe better to test if the object can return an iter me

Re: [Tutor] recursive problem

2010-09-09 Thread Steven D'Aprano
On Fri, 10 Sep 2010 01:05:22 am Joel Goldstick wrote: > On Thu, Sep 9, 2010 at 10:26 AM, Luke Paireepinart > > wrote: > > Shouldn't there be a way to do this without type checking? Duck > > typing! > > > > Your post got me thinking. Maybe better to test if the object can > > return > an iter metho

Re: [Tutor] recursive problem

2010-09-09 Thread Joel Goldstick
On Thu, Sep 9, 2010 at 12:07 PM, Steven D'Aprano wrote: > On Fri, 10 Sep 2010 01:05:22 am Joel Goldstick wrote: > > On Thu, Sep 9, 2010 at 10:26 AM, Luke Paireepinart > > > > wrote: > > > Shouldn't there be a way to do this without type checking? Duck > > > typing! > > > > > > Your post got me thi

Re: [Tutor] recursive problem

2010-09-09 Thread Luke Paireepinart
Nope Joel, that's what I meant. Remember EAFP over LBYL! I'm not sure the best way to make sure the object is iterable though. Sent from my iPhone On Sep 9, 2010, at 11:41 AM, Joel Goldstick wrote: > > > On Thu, Sep 9, 2010 at 12:07 PM, Steven D'Aprano wrote: > On Fri, 10 Sep 2010 01:05:22

[Tutor] Python social network / cms components?

2010-09-09 Thread Igor Choromanski
Hi, After much research, I've come up with a list of what I think might be the best way of putting together a Python based social network/cms, but have some questions about how some of these components fit together. Before I ask about the particular components, here are some of the key features o

[Tutor] Random list exercise

2010-09-09 Thread lists
Hi tutors, Still on my Python learning journey! I've just competed an exercise which asks the student to "Create a program that creates a list of words in random order. This program should print all the words and not repeat any." I've printed the list for my own needs. The list randwords aims to a

Re: [Tutor] Random list exercise

2010-09-09 Thread Joel Goldstick
On Thu, Sep 9, 2010 at 4:51 PM, lists wrote: > Hi tutors, > > Still on my Python learning journey! I've just competed an exercise > which asks the student to "Create a program that creates a list of > words in random order. This program should print all the words and not > repeat any." I've print

Re: [Tutor] Random list exercise

2010-09-09 Thread Joel Goldstick
On Thu, Sep 9, 2010 at 5:42 PM, Joel Goldstick wrote: > > > On Thu, Sep 9, 2010 at 4:51 PM, lists wrote: > >> Hi tutors, >> >> Still on my Python learning journey! I've just competed an exercise >> which asks the student to "Create a program that creates a list of >> words in random order. This p

Re: [Tutor] Random list exercise

2010-09-09 Thread lists
> > > On Thu, Sep 9, 2010 at 4:51 PM, lists wrote: >> >> Hi tutors, >> >> Still on my Python learning journey! I've just competed an exercise >> which asks the student to "Create a program that creates a list of >> words in random order. This program should print all the words and not >> repeat an

Re: [Tutor] Random list exercise

2010-09-09 Thread lists
>>> >>> Hi tutors, >>> >>> Still on my Python learning journey! I've just competed an exercise >>> which asks the student to "Create a program that creates a list of >>> words in random order. This program should print all the words and not >>> repeat any." I've printed the list for my own needs. T

Re: [Tutor] Random list exercise

2010-09-09 Thread lists
>>> Several small and not so small points: >>> >>> 1. you assign wordslen each pass through your loop.  While it doesn't >>> matter in a small loop, it wastes time on the order of the size of your >>> list.  Instead move wordslen = len(...  above your while loop.  Any time you >>> put code in a loo

Re: [Tutor] Mutable Properties

2010-09-09 Thread Christopher King
sorry, accidentally hit reply instead of reply to all On Thu, Sep 9, 2010 at 8:42 AM, Steven D'Aprano wrote: > Please don't reply privately to me unless you mean to ask me something > private or personal. > > If you send your reply to the tutor list, I'll respond there. > > > Regards, > > > > --

Re: [Tutor] Random list exercise

2010-09-09 Thread Christopher King
forgot to send it to the list On Thu, Sep 9, 2010 at 9:58 PM, Christopher King wrote: > you could try random.shuffle and save a lot of time, it takes a mutable > sequence (like a list) and shuffles it > > > On Thu, Sep 9, 2010 at 6:39 PM, lists wrote: > >> >>> Several small and not so small poin