Implement `String#parse_mana_cost`, which parses [Magic: the Gathering mana costs](http://mtgsalvation.gamepedia.com/Mana_cost) expressed as a string and returns a `Hash` with keys being kinds of mana, and values being the numbers.

Don't include any mana types equal to zero.

Format is:

* optionally natural number representing total amount of generic mana (use key `*`)
* optionally followed by any combination of `w`, `u`, `b`, `r`, `g` (case insensitive in input, return lower case in output), each representing one mana of specific color.

If case of Strings not following specified format, return `nil/null/None`.

Difficulty: introductory

Starter code:

def parse_mana_cost(mana):
	

Solutions:

import re
def parse_mana_cost(mana):
    n={c:mana.lower().count(c) for c in 'wubrg' if mana.lower().count(c)>0}
    m=re.split(r'\D',mana)   
    if sum(n.values())+sum([len(c) for c in m]) != len(mana): return None
    p = sum([int(c) for c in m if c!=''])
    if p>0: n['*']=p
    return n


import re

def parse_mana_cost(mana):
    m = re.match(r"(\d*)([wubrg]*)\Z", mana.lower())
    if m is None:
        return
    g, c = m.groups()
    result = {} if g in ("", "0") else {"*": int(g)}
    result.update({k: c.count(k) for k in set(c)})
    return result

from collections import Counter

def parse_mana_cost(mana):
    if mana != mana.strip() or [c for c in mana.lower() if c not in '0123456789 wubrg']:
        return None
        
    return Counter(''.join(parse(w) for w in mana.lower().split()))
    
def parse(w):
    s = '0'
    while w and w[0].isdigit():
        s, w = s + w[0], w[1:]    
    return w + '*' * int(s)

import re
def parse_mana_cost(mana):
        retval = {}
        mana = mana.lower()
        m = re.match(r'\A(\d*)([wubrg]*)\Z', mana)
        if m:
                if m.group(1) and int(m.group(1)) > 0:
                                retval['*'] = int(m.group(1))
                if m.group(2):
                        l = list(m.group(2))
                        print(l)
                        if l.count('w') > 0:
                                retval['w'] = l.count('w')
                        if l.count('u') > 0:
                                retval['u'] = l.count('u')
                        if l.count('b') > 0:
                                retval['b'] = l.count('b')
                        if l.count('r') > 0:
                                retval['r'] = l.count('r')
                        if l.count('g') > 0:
                                retval['g'] = l.count('g')
                return retval


import re
from collections import Counter


def parse_mana_cost(mana):
    for cnt, chrs in re.findall(r"\A(\d*)([wubrg]*)\Z", mana.lower() or "0"):
        result = {"*": int(cnt or 0), **Counter(chrs)}
        return {key: result[key] for key in result if result[key]}

from collections import Counter
import re

def parse_mana_cost(s):
    s = s.lower()
    if re.match(r"\d*[wubrg]*\Z", s):
        r = {x: s.count(x) for x in set(s) if x.isalpha()}
        return s and s[0].isdigit() and int(s[0]) and r.update({"*": int(re.match(r"\d+", s).group())}) or r

import re
def parse_mana_cost(m):
    if not m : return {}
    if not re.match(r'^[\dwubrg]+$',m,re.I) or '\n' in m : return 
    r1,r = re.findall(r'[wubrg]',m,re.I), re.search(r'^[0-9]*',m)
    r,d = r.group() if r else '',{}
    if r!='0' and r : d['*'] = int(r)
    for i in m[len(r):] : d[i.lower()] = d.get(i.lower(),0)+1
    return d

import re

def parse_mana_cost(mana):
    mana = mana.lower()
    valid = ['w','u','r','g','b']
    dic = {}
    regex = re.compile(r'(\d*)([wubrg]*)')
    match = regex.search(mana)
    
    for x in list(mana):
        if x in valid:
            dic[x] = dic[x]+1 if x in dic else 1
            
    if match.group(1) and match.group(1) != '0':
        dic['*'] = int(match.group(1))

    return dic if ''.join(match.group())==mana else None

from itertools import groupby
import re
def parse_mana_cost(mana):
    result = {}
    pattern = re.compile(r'\d*[wurbg]*', re.I)
    manacost = pattern.match(mana).group()
    if mana in ['', '0']:
        return {}
    if manacost == None or len(mana) != len(manacost):
        return None
    colors, colorless = '', ''
    for i in manacost:
        if i.isalpha():
            colors += i
        else:
            colorless +=i
    if colorless not in ['0', '']:
        result['*'] = int(colorless)
    colors = ''.join(sorted(list(colors)))
    for key, count in groupby(colors):
        result[key.lower()] = len(list(count))
    return result