Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #41684
| Path | csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <tampucciolina@libero.it> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.009 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'syntax': 0.03; 'test,': 0.05; '0),': 0.09; 'terry': 0.09; 'def': 0.10; 'index': 0.13; "'a',": 0.16; "'c',": 0.16; "'d',": 0.16; '2),': 0.16; 'letter:': 0.16; 'loops': 0.16; 'passed.': 0.16; 'reedy': 0.16; 'wrote:': 0.17; 'copied': 0.17; 'jan': 0.18; 'tests': 0.18; 'code,': 0.18; 'to:name:python-list@python.org': 0.20; 'subject:problem': 0.22; 'errors': 0.23; 'header:In-Reply-To:1': 0.25; 'wrote': 0.26; 'assert': 0.29; 'index,': 0.29; 'url:mailman': 0.29; 'url:python': 0.32; 'url:listinfo': 0.32; 'to:addr:python-list': 0.33; 'code:': 0.33; 'version': 0.34; 'pm,': 0.35; 'url:org': 0.36; 'subject:with': 0.36; 'thank': 0.36; 'charset:us-ascii': 0.36; 'well.': 0.37; 'subject:: ': 0.38; 'possible.': 0.38; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'received:192.168': 0.40; 'url:mail': 0.40; 'header:Message-Id:1': 0.62; 'gone': 0.64; 'following.': 0.65; 'news': 0.68; 'soon': 0.70; 'exercise,': 0.84; 'ore': 0.84; 'received:212.52.84': 0.84; 'received:libero.it': 0.84; 'received:212.52': 0.91 |
| X-CTCH-Spam | Unknown |
| X-CTCH-RefID | str=0001.0A0C0208.514C0278.017C,ss=1,re=0.000,fgs=0 |
| X-libjamoibt | 1823 |
| Content-Type | text/plain; charset=us-ascii |
| Mime-Version | 1.0 (Mac OS X Mail 6.2 \(1499\)) |
| Subject | Re: problem with function |
| From | leonardo <tampucciolina@libero.it> |
| In-Reply-To | <kig4ko$hus$1@ger.gmane.org> |
| Date | Fri, 22 Mar 2013 08:04:23 +0100 |
| Content-Transfer-Encoding | quoted-printable |
| References | <870147F2-AF34-456A-BDF3-12C0A2F67A69@icloud.com> <kig4ko$hus$1@ger.gmane.org> |
| To | "python-list@python.org" <python-list@python.org> |
| X-Mailer | Apple Mail (2.1499) |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.3610.1363935999.2939.python-list@python.org> (permalink) |
| Lines | 44 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1363935999 news.xs4all.nl 6951 [2001:888:2000:d::a6]:42557 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:41684 |
Show key headers only | View raw
thank you all
Il giorno 22/mar/2013, alle ore 00:20, Terry Reedy <tjreedy@udel.edu> ha scritto:
> On 3/21/2013 2:31 PM, leonardo selmi wrote:
>
>> i wrote the following code:
>>
>> def find(word, letter):
>> index = 0
>> while index < len(word):
>> if word[index] == letter:
>> return index
>> index = index + 1
>> return -1
>
> Since this is a learning exercise, consider the following.
>
> def find(word, letter):
> for index, let in enumerate(word):
> if let == letter:
> return index
> return -1
>
> for w, l, n in (('abc', 'a', 0), ('abc', 'c', 2), ('abc', 'd', -1)):
> assert find(w, l) == n
> print("no news is good news")
>
> I copied the code, wrote the test, ran it, and it passed. I then re-wrote until syntax errors were gone and the new version passed. For loops are specialized, easier-to-write version of while loops that scan the items of a collection (iterable). Learn them and use them well. Learn to write automated tests as soon as possible.
>
> --
> Terry Jan Reedy
>
> --
> http://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: problem with function leonardo <tampucciolina@libero.it> - 2013-03-22 08:04 +0100
csiph-web