Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #77377
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.fsmpi.rwth-aachen.de!newsfeed0.kamp.net!newsfeed.kamp.net!feeder1.cambriumusenet.nl!feed.tweaknews.nl!194.109.133.81.MISMATCH!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python@mrabarnett.plus.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.002 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'indices': 0.07; 'string': 0.09; 'integers': 0.09; 'iterate': 0.09; 'logic': 0.09; 'prefix': 0.09; 'sentence': 0.09; 'def': 0.12; 'changes': 0.15; '>>on': 0.16; 'btw': 0.16; 'cleaner': 0.16; 'dark.': 0.16; 'from:addr:mrabarnett.plus.com': 0.16; 'from:addr:python': 0.16; 'from:name:mrab': 0.16; 'index.': 0.16; 'message-id:@mrabarnett.plus.com': 0.16; 'received:192.168.1.4': 0.16; 'shooting': 0.16; 'stem': 0.16; 'typeerror:': 0.16; 'index': 0.16; 'wrote:': 0.18; 'trying': 0.19; '>>>': 0.22; 'input': 0.22; 'example': 0.22; 'aug': 0.22; 'print': 0.22; 'header:User- Agent:1': 0.23; 'error': 0.23; 'why.': 0.24; 'looks': 0.24; '15,': 0.26; 'this:': 0.26; 'skip:" 20': 0.27; 'header:In-Reply-To:1': 0.27; 'tried': 0.27; 'michael': 0.29; "doesn't": 0.30; 'work.': 0.31; 'getting': 0.31; 'fault': 0.31; 'index,': 0.31; 'file': 0.32; '(most': 0.33; 'something': 0.35; 'test': 0.35; 'version': 0.36; 'skip:> 10': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'list,': 0.38; 'pm,': 0.38; 'little': 0.38; 'recent': 0.39; 'itself': 0.39; 'to:addr:python.org': 0.39; 'letters': 0.60; 'solve': 0.60; 'break': 0.61; 'entire': 0.61; 'kind': 0.63; 'happen': 0.63; 'skip:n 10': 0.64; 'different': 0.65; 'latest': 0.67; '26,': 0.68; 'subject:This': 0.74; 'idiom': 0.84; 'popup': 0.84; 'subject:interesting': 0.84; 'directly.': 0.95 |
| X-CM-Score | 0.00 |
| X-CNFS-Analysis | v=2.1 cv=Uv7tNoAB c=1 sm=1 tr=0 a=0nF1XD0wxitMEM03M9B4ZQ==:117 a=0nF1XD0wxitMEM03M9B4ZQ==:17 a=0Bzu9jTXAAAA:8 a=u9EReRu7m0cA:10 a=fmrOnJK_v7MA:10 a=fIYvK4aQMKUA:10 a=ihvODaAuJD4A:10 a=IkcTkHD0fZMA:10 a=EBOSESyhAAAA:8 a=pGLkceISAAAA:8 a=ACoGqrX--49rzdtXkBEA:9 a=QEXdDO2ut3YA:10 a=MSl-tDqOz04A:10 |
| X-AUTH | mrabarnett:2500 |
| Date | Mon, 01 Sep 2014 01:23:36 +0100 |
| From | MRAB <python@mrabarnett.plus.com> |
| User-Agent | Mozilla/5.0 (Windows NT 6.3; WOW64; rv:24.0) Gecko/20100101 Thunderbird/24.6.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | Re: This could be an interesting error |
| References | <pm270ap6g01k6a5ip10ij1lgtebsrv00mr@4ax.com> <mailman.13668.1409523047.18130.python-list@python.org> <2jc70at4qcpqmbes72r2f0tsjk8up0j6mn@4ax.com> |
| In-Reply-To | <2jc70at4qcpqmbes72r2f0tsjk8up0j6mn@4ax.com> |
| Content-Type | text/plain; charset=UTF-8; format=flowed |
| Content-Transfer-Encoding | 7bit |
| 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 | <https://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 | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.13672.1409531019.18130.python-list@python.org> (permalink) |
| Lines | 104 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1409531019 news.xs4all.nl 2843 [2001:888:2000:d::a6]:41276 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:77377 |
Show key headers only | View raw
On 2014-09-01 01:04, Seymore4Head wrote:
> On Sun, 31 Aug 2014 16:10:27 -0600, Michael Torrie <torriem@gmail.com>
> wrote:
>
>>On 08/31/2014 03:02 PM, Seymore4Head wrote:
>>> def pigword(test):
>>> for x in range(len(test)):
>>> if test[x] in "AEIOUaeiou":
>>> stem = test [x:]
>>> prefix = test [:x]
>>> pigword = stem + prefix + "ay"
>>> print ("Stem ",stem)
>>> print ("Prefix",prefix)
>>> print (pigword)
>>> break
>>> return (pigword)
>>
>>So, what do you think will happen if the word contains no vowels? Where
>>is pigword defined?
>>
>>> for x in range(len(newex)):
>>> sentence = sentence + pigword(newex[x])+ " "
>>> print (sentence)
>>> wait = input (" Wait")
>>
>>You don't need to iterate over range(len(blah)). The standard idiom
>>when you need index as well as the item itself is to iterate over
>>enumerate(). Or if you don't need the index, just iterate directly.
>>You can iterate directly over the list, or the letters in the word,
>>optionally getting an index. It's much cleaner and less error prone.
>>Consider something like:
>>
>>def pigword(word):
>> for x,letter in enumerate(word):
>> # x is index (position), letter is the value at that index
>> if letter in "AEIOUaeiou":
>> ...
>>
>>for word in list_of_words:
>> sentence = sentence + pigword(word) + " "
>> ...
>>
>>That doesn't solve your little logic problem, though I think you can
>>figure that part out easily!
>>
> I am still kind of shooting in the dark.
>
> I wanted to try your example and it doesn't seem to work.
> This is the latest version of changes I have made so the entire
> program looks like this:
>
> newex='Hey buddy get away from my car'
> newex = newex.split()
> sentence=""
>
> print (newex)
> wait = input (" Wait")
>
> def pigword(test):
> for x in range(len(test)):
> if test[x] in "AEIOUYyaeiou":
> stem = test [x:]
> prefix = test [:x]
> pigword = stem + prefix + "ay"
> print ("Stem ",stem)
> print ("Prefix",prefix)
> print (pigword)
> break
> return (pigword)
>
> for x in range(len(newex)):
> sentence = sentence + pigword(newex[x])+ " "
> print (sentence)
> wait = input (" Wait")
>
> Trying to use your example
>>def pigword(word):
>> for x,letter in enumerate(word):
>> # x is index (position), letter is the value at that index
>> if letter in "AEIOUaeiou":
> BTW I added "AEIOUYyaeiou" y as a vowel.
>
> I tried changing:
> for x in range(len(test)):
> to
> for x in enumerate(test):
>
> That causes an error to popup in a different place. I don't
> understand why.
> Traceback (most recent call last):
> File "C:\Functions\piglatin.py", line 26, in <module>
> sentence = sentence + pigword(newex[x])+ " "
> File "C:\Functions\piglatin.py", line 15, in pigword
> if test[x] in "AEIOUYyaeiou":
> TypeError: string indices must be integers
>
Try printing out x. That should give you a clue!
> Since you included:
>>for word in list_of_words:
>> sentence = sentence + pigword(word) + " "
> I take it you anticipated a fault here. I don't understand why.
>
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 17:02 -0400
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 17:07 -0400
Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-31 22:38 +0100
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:04 -0400
Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-31 23:26 +0100
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:42 -0400
Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 00:21 +0100
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:08 -0400
Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 01:56 +0100
Re: This could be an interesting error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-01 12:53 +1000
Re: This could be an interesting error Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-09-01 07:34 +0100
Re: This could be an interesting error Ned Batchelder <ned@nedbatchelder.com> - 2014-08-31 22:12 -0400
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 22:54 -0400
Re: This could be an interesting error Larry Hudson <orgnut@yahoo.com> - 2014-08-31 21:55 -0700
Re: This could be an interesting error Chris Angelico <rosuav@gmail.com> - 2014-09-01 15:12 +1000
Re: This could be an interesting error Rustom Mody <rustompmody@gmail.com> - 2014-08-31 23:53 -0700
Re: This could be an interesting error MRAB <python@mrabarnett.plus.com> - 2014-08-31 22:53 +0100
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:07 -0400
Re: This could be an interesting error Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-01 12:12 +1000
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 22:13 -0400
Re: This could be an interesting error Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-09-01 19:25 +1200
Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 16:10 -0600
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 18:31 -0400
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:04 -0400
Re: This could be an interesting error MRAB <python@mrabarnett.plus.com> - 2014-09-01 01:23 +0100
Re: This could be an interesting error Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-08-31 20:35 -0400
Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 22:15 -0600
Re: This could be an interesting error Michael Torrie <torriem@gmail.com> - 2014-08-31 22:52 -0600
csiph-web