# RegExp Fun #1 - When I miss few days of gym

## Disclaimer

The background story of this Kata is 100% fiction.  Any resemblance to real people or real events is **nothing more than a coincidence** and should be regarded as such.

## Background Story

You are a person who loves to go to the gym everyday with the squad of people that you've known since early childhood.  However, you recently contracted a sickness that forced you to stay at home for over a week.  As you see your body getting weaker and weaker every day and as you see your biceps and triceps disappearing, you can't help but lay in bed and cry.  You're usually an optimistic person but this time negative thoughts come to your head ... 

![When I miss few days of gym](https://pics.onsizzle.com/Instagram-faf8c9.png)


## Task

As can be seen from the funny image above (or am I the only person to find the picture above hilarious?) there is lots of slang.  Your task is to define a function ```gymSlang``` which accepts a string argument and does the following:

1. Replace *all* instances of ```"probably"``` to ```"prolly"```
2. Replace *all* instances of ```"i am"``` to ```"i'm"```
3. Replace *all* instances of ```"instagram"``` to ```"insta"```
4. Replace *all* instances of ```"do not"``` to ```"don't"```
5. Replace *all* instances of ```"going to"``` to ```"gonna"```
6. Replace *all* instances of ```"combination"``` to ```"combo"```

Your replacement regexes **should be case-sensitive**, only replacing the words above with slang if the detected pattern is in **lowercase**.  However, please note that apart from 100% lowercase matches, you will **also have to replace matches that are correctly capitalized** (e.g. ```"Probably" => "Prolly"``` or ```"Instagram" => "Insta"```).

Finally, your code will be tested to make sure that you have used **RegExp** replace in your code.

Enjoy :D

Difficulty: introductory

Starter code:

def gym_slang(phrase):
	

Solutions:
import re

def gym_slang(phrase):
    phrase = re.sub(r'([pP])robably', r'\1rolly', phrase)
    phrase = re.sub(r'([iI]) am', r"\1'm", phrase)
    phrase = re.sub(r'([iI])nstagram', r'\1nsta', phrase)
    phrase = re.sub(r'([dD])o not', r"\1on't", phrase)
    phrase = re.sub(r'([gG])oing to', r'\1onna', phrase)
    phrase = re.sub(r'([cC])ombination', r'\1ombo', phrase)
    
    return phrase

from re import sub

dict = {"([pP]ro)bably": r"\1lly",
        "([iI]) am": r"\1'm",
        "([iI]nsta)gram": r"\1",
        "([dD]o) not": r"\1n't",
        "([gG]o)ing to": r"\1nna",
        "([cC]omb)ination": r"\1o"}

def gym_slang(phrase):
    for k, v in dict.items():
        phrase = sub(k, v, phrase)
    return phrase

import re

def gym_slang(phrase, *args):
    def repl_f (repl):
        def g (match):
            return repl.capitalize () if match.group (0) [0].isupper () else repl
        return g
        
    r = phrase
    r = re.sub ('(p|P)robably', repl_f ('prolly'), r)
    r = re.sub ('(i|I) am', repl_f ('i\'m'), r)
    r = re.sub ('(i|I)nstagram', repl_f ('insta'), r)
    r = re.sub ('(d|D)o not', repl_f ('don\'t'), r)
    r = re.sub ('(g|G)oing to', repl_f ('gonna'), r)
    r = re.sub ('(c|C)ombination', repl_f ('combo'), r)
    return r


from functools import reduce
REPLS = (
    ('probably', 'prolly'), ('Probably', 'Prolly'), ('i am', "i'm"),
    ('I am', "I'm"), ('instagram', 'insta'), ('Instagram', 'Insta'),
    ('do not', "don't"), ('Do not', "Don't"), ('going to', 'gonna'),
    ('Going to', 'Gonna'), ('combination', 'combo'), ('Combination', 'Combo')
)


def gym_slang(s, _=None):
    return reduce(lambda a, kv: a.replace(*kv), REPLS, s)


def gym_slang(phrase):
    return phrase.replace("probably", "prolly").replace("Probably", "Prolly").replace("i am", "i'm").replace("I am", "I'm").replace("instagram", "insta").replace("Instagram", "Insta").replace("do not", "don't").replace("Do not", "Don't").replace("going to", "gonna").replace("Going to", "Gonna").replace("combination", "combo").replace("Combination", "Combo")

import re
r = re.findall(r"\"(\w)(.*?)\".*?\"\w(.*?)\"", """
    Replace all instances of "probably" to "prolly"
    Replace all instances of "i am" to "i'm"
    Replace all instances of "instagram" to "insta"
    Replace all instances of "do not" to "don't"
    Replace all instances of "going to" to "gonna"
    Replace all instances of "combination" to "combo"
    """)

def gym_slang(s):
    for a, b, c in r: s = re.sub("(?<=[%s%s])%s" % (a, a.upper(), b), c, s)
    return s

from functools import partial
import re
def gym_slang(phrase):
    def repl(match):
        def check_upper(word, match):
            return word.capitalize() if match[0].isupper() else word
        check = partial(check_upper, match=match.group())
        if match.group() == match.group(1):
            return check("prolly")
        if match.group() == match.group(2):
            return check("i'm")
        if match.group() == match.group(3):
            return check("insta")
        if match.group() == match.group(4):
            return check("don't")
        if match.group() == match.group(5):
            return check("gonna")
        if match.group() == match.group(6):
            return check("combo")    
    return re.sub(r"(?i)(probably)|(i am)|(instagram)|(do not)|(going to)|(combination)", repl, phrase)

import functools 
import re
gym_slang = lambda phrase: \
    functools.reduce \
    (
        lambda s, u: re.sub(*u, s),
        (
            ('(?<=[Pp])(robably)', 'rolly'),
            ('(?<=[Ii])\sam', '\'m'),
            ('(?<=[Ii])nstagram', 'nsta'),
            ('(?<=[Dd])o\snot', 'on\'t'),
            ('(?<=[Gg])oing\sto', 'onna'),
            ('(?<=[Cc])ombination', 'ombo')
        ),
        phrase
    )

import re
changes = {'probably':'prolly','Probably':'Prolly','i am':'i\'m','I am':'I\'m','instagram':'insta',
           'Instagram':'Insta','do not':'don\'t','Do not':'Don\'t','going to':'gonna','Going to':'Gonna',
           'combination':'combo','Combination':'Combo'}


def gym_slang(phrase):
    for k in changes.keys():
        if k in phrase:
            phrase = re.sub(k,changes[k],phrase)
    return phrase

import re

def gym_slang(phrase):
    s = {r"(P|p)robably": "\\1rolly",
         r"(I|i) am": "\\1'm",
         r"(I|i)nstagram": "\\1nsta",
         r"(D|d)o not": "\\1on't",
         r"(G|g)oing to": "\\1onna",
         r"(C|c)ombination": "\\1ombo"}
    for k, v in s.items():
        phrase = re.sub(k, v, phrase)
    return phrase