Coding Challenge: HipsterPy

Coding Challenge: HipsterPy

27 Mar, 2017. | By: AceLewis


The coding challenge here is to “Hipsterfy” a sentence by removing the last vowel in the word as long as is is not also the first letter of a word.

Sections

  • HipsterPy
  • Solution
  • Conclusion

HipsterPy

In HipsterPy I will “Hipsterfy” words or sentences in Python. The challenge is eaily done in Regex so can be re-created in any language that has Regex, which is most languages. All that needs to be done is to remove the last vowel in every word in a sentence, the vowel e.g: “A Hipster follows the latest trends and fashions.” goes to “A Hipstr follws th latst trnds and fashins.”.

Solutions

The solution to this problem is in Regex, the solution can be found on my GitHub and is also shown below.

It is basically just Regex, I will break down the Regex to explain the steps.

r"(?i)([^\s])[aeiou]([^aeiou]*)\b"

The first part (?i) means case insensitive for the whole Regex. The ([^\s]) means group 1 will be any single character that is not whitespace, [aeiou] is simply match any vowel. ([^aeiou]*) is get all characters that are not vowels (including no letters at all) after the matched vowel and they will be in group 2, and finally \b is a word bondary.

For example in "HipsterPy" you match "terPy" with "t" being in group 1 and "rPy" being in group 2. You then substitute the whole match "terPy" with group 1 and 2 added together "trPy", this substitution gives you "HipstrPy".

Conclusion

I have shown how Regex can easily solve a problem with a solution that is easy to understand (so long as you know Regex) and is much shorter than other methods that could be used. I do like Regex as it is very powerful for matching strings in text however it does have its limits and can easily become hard to read for more complex problems.

Subscribe

Subscribe to this blog via RSS.

Recent Blog Posts

Recent Snippets

All Blog Posts and Snippets

Click here to view all blog and snippets.

Popular Tags

Adblock (2) Ethics (1) Adverts (2) Images (1) Formats (1) Zeronet (2) P2p (3) Dns (1) Zookos triangle (1) Data (2) Maths (1) Bitcoin (1) Blockchain (1) Svg (1) Python (2) Regex (2) Coding (2) Coding challenge (2) Repl.it (1) Emoji (2) Automation (2)

About me

I am interested in Physics, Maths, Programming and also play a few games in my spare time. I have an interest in data and have made webscrapers to gather and process information, I am currently looking into nice ways to display information easily in infographics using Python. I can code in Matlab, Python and have also made a Steam trading bot in Node.JS.

Social Links