Ad

From a single string, find the number of letters for each letter in "duck", find how many "duck"s you have and return it in a dictionary

Example:
"ddduuccckkkkk"

returns { "d":3, "u":2, "c":3, "k":5, "ducks":2 }

Example 2:
"ddddduuuuuccccckkkkk"

return { "d":5, "u":5, "c":5, "k":5, "ducks":5 }

def duck_duck(a):
    return

From a single string, find the number of letters for each letter in "duck", find how many "duck"s you have and return it in a dictionary

Example:
"ddduuccckkkkk"

returns { "d":3, "u":2, "c":3, "k":5, "ducks":2 }

Example 2:
"ddddduuuuuccccckkkkk"

return { "d":5, "u":5, "c":5, "k":5, "ducks":5 }

def duck_test(a):
    duck_dict = {'d': 0, 'u': 0, 'c': 0, 'k': 0, 'ducks': 0}
    for i in a.lower():
        if i in duck_dict and i != 's':
            duck_dict[i] += 1
    duck_dict['ducks'] = min(duck_dict[k] for k in 'duck')
    return duck_dict

Find the letters below in a list

'D', 'U', 'C', 'K'

Return the amount of times the word 'DUCK' can be spelled out

Note: lowercase and uppercase letters should be used in this problem

def save_ducks(flocks):
    quack = madducks = 0
    for duck in flocks.upper():
        if duck == "DUCK"[quack]:
            quack += 1
            if quack == 4:
                madducks += 1
                quack = 0
    return madducks