Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103659 > unrolled thread

Help

Started bytomwilliamson115@gmail.com
First post2016-02-28 11:58 -0800
Last post2016-03-04 21:20 +0000
Articles 8 — 6 participants

Back to article view | Back to comp.lang.python


Contents

  Help tomwilliamson115@gmail.com - 2016-02-28 11:58 -0800
    Re: Help jacob Kruger <jacob@blindza.co.za> - 2016-02-28 22:50 +0200
      Re: Help tomwilliamson115@gmail.com - 2016-02-29 04:53 -0800
        Re: Help Joel Goldstick <joel.goldstick@gmail.com> - 2016-02-29 08:05 -0500
          Re: Help Grant Edwards <invalid@invalid.invalid> - 2016-02-29 15:49 +0000
        Re: Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-02-29 13:41 +0000
        Re: Help Tom P <werotizy@freent.dd> - 2016-03-04 22:06 +0100
          Re: Help Mark Lawrence <breamoreboy@yahoo.co.uk> - 2016-03-04 21:20 +0000

#103659 — Help

Fromtomwilliamson115@gmail.com
Date2016-02-28 11:58 -0800
SubjectHelp
Message-ID<6cdcd063-1c22-4f08-900c-f3260a543018@googlegroups.com>
I need to write a program that allows the user to enter a sentence then asks them which word they wish to find- and then tell them the position that word was within the sentence. 

E.g. Please help with this code 
Then they enter help it would return that it appears in the 2nd position in the sentence. 

From what I gather it appears to be a list function but I am struggling to come up with a solution. 

Thanks.

[toc] | [next] | [standalone]


#103661

Fromjacob Kruger <jacob@blindza.co.za>
Date2016-02-28 22:50 +0200
Message-ID<mailman.25.1456693051.9760.python-list@python.org>
In reply to#103659
On 2016-02-28 9:58 PM, tomwilliamson115@gmail.com wrote:
> I need to write a program that allows the user to enter a sentence then asks them which word they wish to find- and then tell them the position that word was within the sentence.
>
> E.g. Please help with this code
> Then they enter help it would return that it appears in the 2nd position in the sentence.
>
>>From what I gather it appears to be a list function but I am struggling to come up with a solution.
>
> Thanks.
>
Something along lines of loading the sentence into a string, using the 
str.split() function to split it into a list object, then cycling 
through to strip all the spaces and/or punctuation out of the 
elements/items, and then the list.index() function can return the index 
of a word in the list, which is the zero-based position of the item in 
that list.

#something along lines of
s = input("enter sentence")
s.replace(",", "") #do this for all common punctuation characters
l = s.split(" ") #space is actually default
s2 = input("enter word")
i = l.index(s2)
print("Your word is at position " + str(i+1) + " in the sentence")
#end code

That's just typed here in message - HTH

HTH

Jacob Kruger
Blind Biker
Skype: BlindZA
"Roger Wilco wants to welcome you...to the space janitor's closet..."

[toc] | [prev] | [next] | [standalone]


#103702

Fromtomwilliamson115@gmail.com
Date2016-02-29 04:53 -0800
Message-ID<ac3170ba-0450-44df-bd3f-8fef5f39a482@googlegroups.com>
In reply to#103661
Thanks. If a word appears more than once how would I bring back both locations? 

[toc] | [prev] | [next] | [standalone]


#103704

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2016-02-29 08:05 -0500
Message-ID<mailman.6.1456751125.20602.python-list@python.org>
In reply to#103702
On Mon, Feb 29, 2016 at 7:53 AM, <tomwilliamson115@gmail.com> wrote:

> Thanks. If a word appears more than once how would I bring back both
> locations?
>

This is not generally a free coding service.  Fortunately for you Tom,
Jacob was kind enough to do your homework for you.  The problem with doing
someone's homework for them is that they don't learn anything.  Why don't
you go line by line through his code and understand what he has written.  I
think if you do that you will see how to solve the problem of finding then
next match (if there is one)

> --
> https://mail.python.org/mailman/listinfo/python-list
>



-- 
Joel Goldstick
http://joelgoldstick.com/ <http://joelgoldstick.com/stats/birthdays>
http://cc-baseballstats.info/

[toc] | [prev] | [next] | [standalone]


#103723

FromGrant Edwards <invalid@invalid.invalid>
Date2016-02-29 15:49 +0000
Message-ID<nb1p9e$ad7$2@reader1.panix.com>
In reply to#103704
On 2016-02-29, Joel Goldstick <joel.goldstick@gmail.com> wrote:
> On Mon, Feb 29, 2016 at 7:53 AM, <tomwilliamson115@gmail.com> wrote:
>
>> Thanks. If a word appears more than once how would I bring back both
>> locations?
>
> This is not generally a free coding service.  Fortunately for you Tom,
> Jacob was kind enough to do your homework for you.  The problem with doing
> someone's homework for them is that they don't learn anything.

And thus don't compete for the good jobs with us who did learn things.

At least in theory.  

In real life they often still graduate and get hired anyway, get put
in the cubicle next to you, and you spend half your time cleaning up
after them.

-- 
Grant Edwards               grant.b.edwards        Yow! NEWARK has been
                                  at               REZONED!!  DES MOINES has
                              gmail.com            been REZONED!!

[toc] | [prev] | [next] | [standalone]


#103707

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2016-02-29 13:41 +0000
Message-ID<mailman.7.1456753366.20602.python-list@python.org>
In reply to#103702
On 29/02/2016 12:53, tomwilliamson115@gmail.com wrote:
> Thanks. If a word appears more than once how would I bring back both locations?
>

I've no idea without any context, would you please care to elucidate, 
thanks.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#104052

FromTom P <werotizy@freent.dd>
Date2016-03-04 22:06 +0100
Message-ID<djubn1FgjfjU1@mid.individual.net>
In reply to#103702
On 02/29/2016 01:53 PM, tomwilliamson115@gmail.com wrote:
> Thanks. If a word appears more than once how would I bring back both locations?
>

for i, str in enumerate(l): . . . .

[toc] | [prev] | [next] | [standalone]


#104054

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2016-03-04 21:20 +0000
Message-ID<mailman.197.1457126451.20602.python-list@python.org>
In reply to#104052
On 04/03/2016 21:06, Tom P wrote:
> On 02/29/2016 01:53 PM, tomwilliamson115@gmail.com wrote:
>> Thanks. If a word appears more than once how would I bring back both
>> locations?
>>
>
> for i, str in enumerate(l): . . . .

When replying would everybody please quote some context.  All of the 
above is completely meaningless, standing all alone.

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web