Re: [Tutor] another better way to do this ?

2014-01-13 Thread Keith Winston
s*** just got real. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Peter Otten
Alan Gauld wrote: > On 13/01/14 18:22, Peter Otten wrote: >> Peter Otten wrote: > >> In the mean time here is my candidate: >> >> def test(a, b): >> a = iter(a) >> return all(c in a for c in b) > > That's pretty close to my original thoughts. But one question. > Why explicitly convert

Re: [Tutor] another better way to do this ?

2014-01-13 Thread eryksun
On Mon, Jan 13, 2014 at 1:36 PM, Keith Winston wrote: > Yikes, Peter, that's scary. Wow. Yikes, watch the top posting. :) >> In the mean time here is my candidate: >> >> def test(a, b): >> a = iter(a) >> return all(c in a for c in b) Refer to the language reference discussion of compari

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Alan Gauld
On 13/01/14 18:22, Peter Otten wrote: Peter Otten wrote: In the mean time here is my candidate: def test(a, b): a = iter(a) return all(c in a for c in b) That's pretty close to my original thoughts. But one question. Why explicitly convert string a to an iter? The 'in' test would

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Roelof Wobben
> From: keithw...@gmail.com > Date: Mon, 13 Jan 2014 12:56:45 -0500 > Subject: Re: [Tutor] another better way to do this ? > To: rwob...@hotmail.com > CC: tutor@python.org > > On Mon, Jan 13, 2014 at 1:14 AM, Roelof Wobben wrote: > > I have read all comments a

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Keith Winston
Yikes, Peter, that's scary. Wow. On Mon, Jan 13, 2014 at 1:22 PM, Peter Otten <__pete...@web.de> wrote: > Peter Otten wrote: > >> Emile van Sebille wrote: >> >>> On 01/12/2014 12:21 PM, Peter Otten wrote: >>> >>> test("axbxc", "abc") True >>> test("abbxc", "abc") False

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Peter Otten
Peter Otten wrote: > Emile van Sebille wrote: > >> On 01/12/2014 12:21 PM, Peter Otten wrote: >> >> test("axbxc", "abc") >>> True >> test("abbxc", "abc") >>> False >>> >>> Is the second result desired? >> >> No -- the second should match -- you found a test case I didn't... >> >> def t

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Keith Winston
On Mon, Jan 13, 2014 at 1:14 AM, Roelof Wobben wrote: > I have read all comments and im a little bit confused. > About which script are we talkimng about. I have seen a lot. I am talking about the script/approach I posted. Others have posted other scripts. Hopefully you have the capacity, with w

Re: [Tutor] another better way to do this ?

2014-01-13 Thread Roelof Wobben
I have read all comments and im a little bit confused. About which script are we talkimng about. I have seen a lot. Roelof > From: keithw...@gmail.com > Date: Sun, 12 Jan 2014 16:43:40 -0500 > CC: tutor@python.org > Subject: Re: [Tutor] another better way to do this ? > > On

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Keith Winston
On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote: > There's another approach, I think, that's quite easy if order IS important. Alas, there's one further problem with my script, relating to testing multiple sequential letters in product... but I'm not going to say more, I'll leave it as a pro

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Emile van Sebille wrote: > On 01/12/2014 12:21 PM, Peter Otten wrote: > > test("axbxc", "abc") >> True > test("abbxc", "abc") >> False >> >> Is the second result desired? > > No -- the second should match -- you found a test case I didn't... > > def test(a,b): >for ii in a: > i

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Emile van Sebille
On 01/12/2014 12:21 PM, Peter Otten wrote: test("axbxc", "abc") True test("abbxc", "abc") False Is the second result desired? No -- the second should match -- you found a test case I didn't... def test(a,b): for ii in a: if ii not in b: a=a.replace(ii,"") while ii+ii in a: a=a.r

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Emile van Sebille wrote: > On 01/12/2014 06:43 AM, Dave Angel wrote: >> Roelof Wobben Wrote in message: >> >> That documentation says nothing about order. And the test cases >> specifically contradict it. >> >> so try >> >> if set (b) <= set (a): > > or, as the OP specified, if order is rel

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Emile van Sebille
On 01/12/2014 06:43 AM, Dave Angel wrote: Roelof Wobben Wrote in message: That documentation says nothing about order. And the test cases specifically contradict it. so try if set (b) <= set (a): or, as the OP specified, if order is relevant, def test(a,b): for ii in a: if ii no

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Keith Winston
On Sun, Jan 12, 2014 at 2:38 PM, Keith Winston wrote: > Sigh and this line needs to read (if it's going to do what I said): As Alan pointed out, the examples provided do NOT account for order, so if one uses my (corrected) algorithm, you get different results from the examples. Without the f

Re: [Tutor] another better way to do this ?

2014-01-12 Thread eryksun
On Sun, Jan 12, 2014 at 2:38 PM, Keith Winston wrote: > On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote: >> if test: > > Sigh and this line needs to read (if it's going to do what I said): > > if test != -1: Consider the case of `product == "letter"`. Do you want to doub

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Keith Winston
On Sun, Jan 12, 2014 at 2:22 PM, Keith Winston wrote: > if test: Sigh and this line needs to read (if it's going to do what I said): if test != -1: -- Keith ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscr

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Keith Winston
OOps, I never used the "success" boolean in my code, but forgot to remove it. Sorry. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Mark Lawrence
On 12/01/2014 19:22, Keith Winston wrote: On Sun, Jan 12, 2014 at 7:44 AM, Alan Gauld wrote: OK< So there is nothing here about the orders being the same. That makes it much easier. There's another approach, I think, that's quite easy if order IS important. Iterate through the letters of pr

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Keith Winston
On Sun, Jan 12, 2014 at 7:44 AM, Alan Gauld wrote: > OK< So there is nothing here about the orders being the same. > That makes it much easier. There's another approach, I think, that's quite easy if order IS important. Iterate through the letters of product, find() them initially from the begi

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Alan Gauld
On 12/01/14 14:43, Dave Angel wrote: so try if set (b) <= set (a): Ooh, nice! For some reason I've never thought of applying set to a string before. -- Alan G Author of the Learn to Program web site http://www.alan-g.me.uk/ http://www.flickr.com/photos/alangauldphotos _

Re: [Tutor] another better way to do this ?

2014-01-12 Thread eryksun
On Sun, Jan 12, 2014 at 8:21 AM, Peter Otten <__pete...@web.de> wrote: > > OP: You'll get bonus points (from me, so they're pointless points, but > still) if you can solve this (including the fifth apocryphal test case) > using the collections.Counter class. Hint: >>> print(Counter.__sub__.__

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Dave Angel
Roelof Wobben Wrote in message: That documentation says nothing about order. And the test cases specifically contradict it. so try if set (b) <= set (a): -- DaveA Android NewsGroup Reader http://www.piaohong.tk/newsgroup ___ Tutor ma

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Peter Otten
Alan Gauld wrote: > On 12/01/14 08:12, Roelof Wobben wrote: > >> # Write a Python procedure fix_machine to take 2 string inputs >> # and returns the 2nd input string as the output if all of its >> # characters can be found in the 1st input string and "Give me >> # something that's not useless nex

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Alan Gauld
On 12/01/14 08:12, Roelof Wobben wrote: # Write a Python procedure fix_machine to take 2 string inputs # and returns the 2nd input string as the output if all of its # characters can be found in the 1st input string and "Give me # something that's not useless next time." if it's impossible. OK

Re: [Tutor] another better way to do this ?

2014-01-12 Thread Roelof Wobben
;Udacity') == 'Udacity' print "Test case 3: ", fix_machine('AEIOU and sometimes y... c', 'Udacity') == 'Udacity' print "Test case 4: ", fix_machine('wsx0-=mttrhix', 't-shirt') == 't-shirt' Roelof &g

Re: [Tutor] another better way to do this ?

2014-01-11 Thread Don Jennings
On Jan 11, 2014, at 4:24 PM, Roelof Wobben wrote: > Hello, > > I try to learn python by following the audicity page. > > Now I have the following problem. > > I have two strings a and b > > Now I have to check if the characters of b are all in a. > But they do have to be in the same ord

[Tutor] another better way to do this ?

2014-01-11 Thread Roelof Wobben
Hello, I try to learn python by following the audicity page. Now I have the following problem. I have two strings a and b Now I have to check if the characters of b are all in a. But they do have to be in the same order. So I thought about this solution. length = len(b) start = 1 wh

Re: [Tutor] another better way to do this ?

2014-01-11 Thread Alan Gauld
On 11/01/14 21:24, Roelof Wobben wrote: I have two strings a and b Now I have to check if the characters of b are all in a. But they do have to be in the same order. I'm not sure exactly what you mean? Can you give some examples of data that pass and that fail the criteria? Your algorithm be