Python Forum
A function for correctly using "a/an" before a word
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
A function for correctly using "a/an" before a word
#1
I want to make a function that, when passed a string containing a single word, returns that word preceded by the indefinite article "a" or "an," depending on which is correct. This would be easy enough to do if the rule we were taught as kids were correct: "a" before a consonant, "an" before a vowel. But it isn't. It's "a" before a consonant sound and "an" before a vowel sound; hence, "an umbrella" but "a unicorn" (YOO-ni-corn). How would you go about writing this function? Would you try to compile an exhaustive list of "exceptions" from online sources or work with some kind of API or what? Also, how would you find out if someone has already done this?
Reply
#2
(Oct-07-2019, 05:51 PM)Exsul1 Wrote: Also, how would you find out if someone has already done this?
Did you try to google it?
First result is close to what you want - https://stackoverflow.com/questions/2033...xts-python

Then looking at the answers you see that you probably will need NLTK
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
(Oct-07-2019, 05:51 PM)Exsul1 Wrote: [ ... ] word preceded by the indefinite article "a" or "an," depending on which is correct. This would be easy enough to do if the rule we were taught as kids were correct: "a" before a consonant, "an" before a vowel. But it isn't. It's "a" before a consonant sound and "an" before a vowel sound; hence, "an umbrella" but "a unicorn" (YOO-ni-corn).

Hi!

Just a thought on linguistics, not on Python:

Although, it seems that the rule for words beginning with an 'h' depends on the sound, it seems that for native speakers, it actually depends on tradition, even on the place you have been grown up, or studied.

Some people say 'a historic occasion', while others 'an historic occasion'.
Some people say 'a herb', while others 'an herb'.
Some people say 'a hotel', while others 'an hotel'.

The same could apply to some other words I've heard using either 'a' or 'an' before them: hysterical, heroic, horrific, and human, and the list is not over.

More on this issue:

http://editingandwritingservices.com/a-o...ng-with-h/

http://www.scribe.com.au/tip-w005.html

https://www.quora.com/Which-article-shou...al-A-or-an

https://www.writing-skills.com/hit-or-my...re-h-words

http://www.stgeorges.co.uk/blog/a-or-an-...r-an-hotel

https://english.stackexchange.com/questi...e-letter-h

https://www.lexico.com/en/grammar/a-hist...oric-event

https://www.merriam-webster.com/words-at...it-a-or-an

All the best,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python Speech recognition, word by word AceScottie 6 9,005 Apr-12-2020, 09:50 AM
Last Post: vinayakdhage
  print a word after specific word search evilcode1 8 830 Oct-22-2019, 08:08 AM
Last Post: newbieAuggie2019
  Python function that uses a word as the encryption key, rather than an integer wak_stephanie 4 1,800 Aug-31-2018, 12:16 PM
Last Post: perfringo
  difference between word: and word[:] in for loop zowhair 2 1,469 Mar-03-2018, 07:24 AM
Last Post: zowhair

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020