Re: SimplePrograms challenge

2007-06-22 Thread [EMAIL PROTECTED]
Ah, I mistook you for someone who gives a shit. - You DID see my post on comp.lang.python and deliberately ignored it. - You then lied and claimed there was no discussion. - You then lied and claimed my example merely duplicated other examples. - You claimed to be offended by my characteriz

Re: SimplePrograms challenge

2007-06-21 Thread pelon
And while I'm at it... Although Guido's tutorial was a great place to start when I first came to python I would have learned more and faster had SimplePrograms existed. My only complaint with the python documentation is the dearth of examples. The PHP documentation is chock full. Steve, You int

Re: SimplePrograms challenge

2007-06-21 Thread pelon
*** New Thread #5 has been bothering me. def greet(name): print 'hello', name greet('Jack') greet('Jill') greet('Bob') Using greet() three times is cheating and doesn't teach much and doesn't have any real world use that #1 can't fulfill. I offer this replacement: def greet(name): """

Re: SimplePrograms challenge

2007-06-21 Thread Pete Forman
Steve Howell <[EMAIL PROTECTED]> writes: > The BankAccount example is about as small of a "complete" class > example that I could come up with, even though it's "complete" only > a basic level. It would be good to have a larger class example > that fleshes out the concept a bit more, even if

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > > An empty list raises an IndexError, a non-iterable > raises TypeError. > This is correct behavior IMHO, there is nothing to > fix. Median should > return an element (or average of two) from its input > and if that is > not meaningful returning None

Re: SimplePrograms challenge

2007-06-20 Thread Pete Forman
Steve Howell <[EMAIL PROTECTED]> writes: >3) The median example raises the question of what > would happen with an empty list. I don't think it's > important to cover that case in the simple example > (it's really the responsibility of the caller IMO not > to call median with nonsense ar

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > Steve Howell <[EMAIL PROTECTED]> writes: > > > Feel free to change the page as you see fit, > although thanks for > > discussing it here first. > > Done. I've moved classes up as unittest depends on > it. > > The changes that I made to classes we

Re: SimplePrograms challenge

2007-06-20 Thread Pete Forman
Steve Howell <[EMAIL PROTECTED]> writes: > Feel free to change the page as you see fit, although thanks for > discussing it here first. Done. I've moved classes up as unittest depends on it. The changes that I made to classes were: 1) Use new style class. 2) Demonstrate Pythonic use of attri

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > Steve Howell <[EMAIL PROTECTED]> writes: > > >> 2) assert is not the simplest example of doctest. > > >> The style should be > >> > >> >>> add_money([0.13, 0.02]) > >> 0.15 > >> >>> add_money([100.01, 99.99]) > >> 200.0 > >> >>>

Re: SimplePrograms challenge

2007-06-20 Thread Pete Forman
Steve Howell <[EMAIL PROTECTED]> writes: >> 2) assert is not the simplest example of doctest. >> The style should be >> >> >>> add_money([0.13, 0.02]) >> 0.15 >> >>> add_money([100.01, 99.99]) >> 200.0 >> >>> add_money([0, -13.00, 13.00]) >> 0.0 >> > > That's not clear

Re: SimplePrograms challenge

2007-06-20 Thread Steve Howell
--- Pete Forman <[EMAIL PROTECTED]> wrote: > André <[EMAIL PROTECTED]> writes: > > > Ok, doctest-based version of the Unit test > example added; so much > > more Pythonic ;-) > > Sorry for being a bit picky but there are a number > of things that I'm > unhappy with in that example. > Your p

Re: SimplePrograms challenge

2007-06-20 Thread Pete Forman
André <[EMAIL PROTECTED]> writes: > Ok, doctest-based version of the Unit test example added; so much > more Pythonic ;-) Sorry for being a bit picky but there are a number of things that I'm unhappy with in that example. 1) It's the second example with 13 lines. Though I suppose that the

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Joe Riopel <[EMAIL PROTECTED]> wrote: > How about this one for recursion and control flow: > > >>> def hcd(m,n): > ... r = m % n > ... if( r > 0 ): > ... hcd(n, r) > ... else: > ... print "hcd = %d" % (n,) > ... > >>> hcd(119, 544) > hcd = 17 > >>> > > It

Re: SimplePrograms challenge

2007-06-14 Thread Joe Riopel
How about this one for recursion and control flow: >>> def hcd(m,n): ... r = m % n ... if( r > 0 ): ... hcd(n, r) ... else: ... print "hcd = %d" % (n,) ... >>> hcd(119, 544) hcd = 17 >>> It calculates the highest common denominator for m and n. Plus it's E1 in

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- rzed <[EMAIL PROTECTED]> wrote: > Hm > > ... and so on. > > In much of Python's documentation, and in this case, > an occasional > working example of use would go FAR in aiding > understanding of the > underlying concept. > I agree with your sentiment 100%. Feel free to change t

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > > How about including a driver? > > Yes, absolutely a good idea. Fortunately, the other > Steve borrowed the > time machine already and added this to the end:: > > for p in iter_primes(): > if p > 1000: break > print p >

Re: SimplePrograms challenge

2007-06-14 Thread Steven Bethard
rzed wrote: > Steven Bethard <[EMAIL PROTECTED]> wrote in >> def iter_primes(): >> # an iterator of all numbers between 2 and +infinity >> numbers = itertools.count(2) >> >> # generate primes forever >> while True >> >> # generate the first number from the iterator, >>

Re: SimplePrograms challenge

2007-06-14 Thread rzed
Steven Bethard <[EMAIL PROTECTED]> wrote in news:[EMAIL PROTECTED]: > Steve Howell wrote: >> --- George Sakkis <[EMAIL PROTECTED]> wrote: >>> from itertools import count, ifilter >>> def sieve(): >>> seq = count(2) >>> while True: >>> p = seq.next() >>> seq = ifilter(p.__r

Re: SimplePrograms challenge

2007-06-14 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: unit.text) > > I posted a slight variant of this, trimmed down a > bit to 21 lines. > Thanks, I think this will be a very useful example. Pinpoint custome

Re: SimplePrograms challenge

2007-06-13 Thread Steven Bethard
Rob Wolfe wrote: > # HTML page > dinner_recipe = ''' > Recipe > > amtunititem > 24slicesbaguette > 2+tbspolive_oil > 1cuptomatoes > 1-2tbspgarlic > 1/2cupParmesan > 1jarpesto > > ''' > > # program > import xml.etree.ElementTree as etree > tree = etree.fromstring(dinner_recipe) > > #import Eleme

Re: SimplePrograms challenge

2007-06-13 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Rob Wolfe wrote: > > Steve Howell wrote: > > > >> I suggested earlier that maybe we post multiple > >> solutions. That makes me a little nervous, to > the > >> extent that it shows that the Python community > has a > >> hard time coming to consens

Re: SimplePrograms challenge

2007-06-13 Thread infidel
# writing/reading CSV files, tuple-unpacking, cmp() built-in import csv writer = csv.writer(open('stocks.csv', 'wb')) writer.writerows([ ('GOOG', 'Google, Inc.', 505.24, 0.47, 0.09), ('YHOO', 'Yahoo! Inc.', 27.38, 0.33, 1.22), ('CNET', 'CNET Networks, Inc.', 8.62, -0.13, -1.49) ]) sto

Re: SimplePrograms challenge

2007-06-13 Thread Steven Bethard
Rob Wolfe wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > >>> I vote for example with ElementTree (without xpath) >>> with a mention of using ElementSoup for invalid HTML. >> Sounds good to me. Maybe something like:: >> >> import xml.etree.ElementTree as etree >> dinner_recipe = ''' >> >>

Re: SimplePrograms challenge

2007-06-13 Thread Rob Wolfe
Steven Bethard <[EMAIL PROTECTED]> writes: >> I vote for example with ElementTree (without xpath) >> with a mention of using ElementSoup for invalid HTML. > > Sounds good to me. Maybe something like:: > > import xml.etree.ElementTree as etree > dinner_recipe = ''' > > 24slicesbaguette > 2+tbspol

Re: SimplePrograms challenge

2007-06-13 Thread Steven Bethard
Rob Wolfe wrote: > Steve Howell wrote: > >> I suggested earlier that maybe we post multiple >> solutions. That makes me a little nervous, to the >> extent that it shows that the Python community has a >> hard time coming to consensus on tools sometimes. > > We agree that BeautifulSoup is the bes

Re: SimplePrograms challenge

2007-06-13 Thread Rob Wolfe
Steve Howell wrote: > I suggested earlier that maybe we post multiple > solutions. That makes me a little nervous, to the > extent that it shows that the Python community has a > hard time coming to consensus on tools sometimes. We agree that BeautifulSoup is the best for parsing HTML. :) > Th

Re: SimplePrograms challenge

2007-06-13 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Stefan Behnel wrote: > > Steven Bethard wrote: > >> If you want to parse invalid HTML, I strongly > encourage you to look into > >> BeautifulSoup. Here's the updated code: > >> > >> import ElementSoup # > http://effbot.org/zone/element-soup.htm

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Stefan Behnel wrote: > Steven Bethard wrote: >> If you want to parse invalid HTML, I strongly encourage you to look into >> BeautifulSoup. Here's the updated code: >> >> import ElementSoup # http://effbot.org/zone/element-soup.htm >> import cStringIO >> >> tree = ElementSoup.parse(cStri

Re: SimplePrograms challenge

2007-06-12 Thread Stefan Behnel
Steven Bethard wrote: > Rob Wolfe wrote: >> Steven Bethard <[EMAIL PROTECTED]> writes: >>> I'd hate to steer a potential new Python developer to a clumsier >> >> "clumsier"??? >> Try to parse this with your program: >> >> page2 = ''' >> URLs >> >> >> http://domain1/page1";>som

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > # print the first 100 primes > for prime in itertools.islice(iter_primes(), > 100): > print prime > Sure. FWIW, in the example I posted, I kept the output loop a little more pedestrian (using an if/break idiom), and I printed pr

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > On 6/12/07, Steve Howell <[EMAIL PROTECTED]> > wrote: > > --- Steven Bethard <[EMAIL PROTECTED]> > wrote: > > > import itertools > > > > > > def iter_primes(): > > > # an iterator of all numbers between 2 and > > > +infinity > > > numbers

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Steve Howell wrote: > --- Steven Bethard <[EMAIL PROTECTED]> wrote: >> How about we just comment it better? >> >> import itertools >> >> def iter_primes(): >> # an iterator of all numbers between 2 and +infinity >> numbers = itertools.count(2) [snip] > > Actually, just one small caveat--

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- I wrote: > [...] was the final straw in converting > me from Python to Perl. Er, Perl to Python. In looking backwards, I started writing backwards. And no, I'm not ever going back to Perl... Boa

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- George Sakkis <[EMAIL PROTECTED]> wrote: > >> from itertools import count, ifilter > >> def sieve(): > >> seq = count(2) > >> while True: > >> p = seq.next() > >> seq = ifilter(p.__rmod__, seq) > >

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Steven Bethard <[EMAIL PROTECTED]> wrote: > Steve Howell wrote: > > --- George Sakkis <[EMAIL PROTECTED]> wrote: > >> from itertools import count, ifilter > >> def sieve(): > >> seq = count(2) > >> while True: > >> p = seq.next() > >> seq = ifilter(p.__rmod__, seq) > >

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Steve Howell wrote: > --- George Sakkis <[EMAIL PROTECTED]> wrote: >> from itertools import count, ifilter >> def sieve(): >> seq = count(2) >> while True: >> p = seq.next() >> seq = ifilter(p.__rmod__, seq) >> yield p [snip] > Is there a way to broaden the problem s

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Rob Wolfe <[EMAIL PROTECTED]> wrote: > > What about simple HTML parsing? As a matter of fact > this is not > language concept, but shows the power of Python > standard library. > Besides, that's very popular problem among newbies. I totally agree with the relevance of this example. FWIW it

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- George Sakkis <[EMAIL PROTECTED]> wrote: > > from itertools import count, ifilter > def sieve(): > seq = count(2) > while True: > p = seq.next() > seq = ifilter(p.__rmod__, seq) > yield p > > > I suspect that it violates your second rule though > :) > I'm g

Re: SimplePrograms challenge

2007-06-12 Thread George Sakkis
On Jun 11, 5:56 pm, Steve Howell <[EMAIL PROTECTED]> wrote: > Hi, I'm offering a challenge to extend the following > page by one good example: > > http://wiki.python.org/moin/SimplePrograms > > Right now the page starts off with 15 examples that > cover lots of ground in Python, but they're still

Re: SimplePrograms challenge

2007-06-12 Thread Steve Howell
--- Rob Wolfe <[EMAIL PROTECTED]> wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: > > > I'd hate to steer a potential new Python developer > > to a clumsier [...] > > [...] > But as far as HTML (not XML) is concerned this is > not very realistic solution. > I think both posted examples wou

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Steven Bethard wrote: > Rob Wolfe wrote: >> Steven Bethard <[EMAIL PROTECTED]> writes: >>> I'd hate to steer a potential new Python developer to a clumsier >> >> "clumsier"??? >> Try to parse this with your program: >> >> page2 = ''' >> URLs >> >> >> http://domain1/page1";>som

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Rob Wolfe wrote: > Steven Bethard <[EMAIL PROTECTED]> writes: >> I'd hate to steer a potential new Python developer to a clumsier > > "clumsier"??? > Try to parse this with your program: > > page2 = ''' > URLs > > > http://domain1/page1";>some page1 > http://domain2/pag

Re: SimplePrograms challenge

2007-06-12 Thread Rob Wolfe
Steven Bethard <[EMAIL PROTECTED]> writes: > I'd hate to steer a potential new Python developer to a clumsier "clumsier"??? Try to parse this with your program: page2 = ''' URLs http://domain1/page1";>some page1 http://domain2/page2";>some page2 ''' > libra

Re: SimplePrograms challenge

2007-06-12 Thread Steven Bethard
Rob Wolfe wrote: > Steve Howell wrote: >> Hi, I'm offering a challenge to extend the following >> page by one good example: >> >> http://wiki.python.org/moin/SimplePrograms > > What about simple HTML parsing? As a matter of fact this is not > language concept, but shows the power of Python standar

Re: SimplePrograms challenge

2007-06-12 Thread Rob Wolfe
Steve Howell wrote: > Hi, I'm offering a challenge to extend the following > page by one good example: > > http://wiki.python.org/moin/SimplePrograms What about simple HTML parsing? As a matter of fact this is not language concept, but shows the power of Python standard library. Besides, that's v

Re: SimplePrograms challenge

2007-06-11 Thread [EMAIL PROTECTED]
On Jun 11, 4:56?pm, Steve Howell <[EMAIL PROTECTED]> wrote: > Hi, I'm offering a challenge to extend the following > page by one good example: > > http://wiki.python.org/moin/SimplePrograms > > Right now the page starts off with 15 examples that > cover lots of ground in Python, but they're still >

Re: SimplePrograms challenge

2007-06-11 Thread Steve Howell
--- John Machin <[EMAIL PROTECTED]> wrote: > On Jun 12, 9:16 am, Steve Howell > <[EMAIL PROTECTED]> wrote: > > > > > One more suggestion--maybe it could exercise a > little > > more of the CVS module, i.e. have something in the > > data that would trip up the ','.split() approach? > > The what

Re: SimplePrograms challenge

2007-06-11 Thread John Machin
On Jun 12, 9:16 am, Steve Howell <[EMAIL PROTECTED]> wrote: > > One more suggestion--maybe it could exercise a little > more of the CVS module, i.e. have something in the > data that would trip up the ','.split() approach? The what approach?? Do you mean blah.split(',') ?? Perhaps like an exampl

Re: SimplePrograms challenge

2007-06-11 Thread John Machin
On Jun 12, 8:51 am, infidel <[EMAIL PROTECTED]> wrote: > # reading CSV files, tuple-unpacking > import csv > > #pacific.csv contains: > #1,CA,California > #2,AK,Alaska > #3,OR,Oregon > #4,WA,Washington > #5,HI,Hawaii > > reader = csv.reader(open('pacific.csv')) For generality and portability, this

Re: SimplePrograms challenge

2007-06-11 Thread Steve Howell
--- infidel <[EMAIL PROTECTED]> wrote: > # reading CSV files, tuple-unpacking > import csv > > #pacific.csv contains: > #1,CA,California > #2,AK,Alaska > #3,OR,Oregon > #4,WA,Washington > #5,HI,Hawaii > > reader = csv.reader(open('pacific.csv')) > for id, abbr, name in reader: > print '%s i

Re: SimplePrograms challenge

2007-06-11 Thread André
On Jun 11, 6:56 pm, Steve Howell <[EMAIL PROTECTED]> wrote: > Hi, I'm offering a challenge to extend the following > page by one good example: > > http://wiki.python.org/moin/SimplePrograms > > Right now the page starts off with 15 examples that > cover lots of ground in Python, but they're still >

Re: SimplePrograms challenge

2007-06-11 Thread infidel
# reading CSV files, tuple-unpacking import csv #pacific.csv contains: #1,CA,California #2,AK,Alaska #3,OR,Oregon #4,WA,Washington #5,HI,Hawaii reader = csv.reader(open('pacific.csv')) for id, abbr, name in reader: print '%s is abbreviated: "%s"' % (name, abbr) -- http://mail.python.org/mai

SimplePrograms challenge

2007-06-11 Thread Steve Howell
Hi, I'm offering a challenge to extend the following page by one good example: http://wiki.python.org/moin/SimplePrograms Right now the page starts off with 15 examples that cover lots of ground in Python, but they're still scratching the surface. (There are also two Eight Queens implementations