Exemple #1
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    sum_chars = 0
    for char in word:
        if LETTER_SCORES.get(char.upper()) is not None:
            sum_chars += LETTER_SCORES.get(char.upper())
    return sum_chars
Exemple #2
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    score = 0
    for letter in word.upper():
        if type(LETTER_SCORES.get(letter)) is int:
            score = score + LETTER_SCORES.get(letter)
    return score
Exemple #3
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    score = 0
    for c in word:
        if LETTER_SCORES.get(c.upper()):
            score += LETTER_SCORES.get(c.upper())
    return score
Exemple #4
0
def calc_word_value(word=""):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    value = 0
    for letter in word:
        if isinstance(LETTER_SCORES.get(letter.upper()), int):
            value += LETTER_SCORES.get(letter.upper())
    return value
Exemple #5
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""

    value = 0
    for letter in word:
        if type(LETTER_SCORES.get(letter[0].upper())) != type(None):
            value = value + int(LETTER_SCORES.get(letter[0].upper()))
    return value
Exemple #6
0
def calc_word_value(word):
    """
    Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES.
    """
    y = (LETTER_SCORES.get(char.upper(), 0) for char in word)
    return sum(y)
Exemple #7
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    result = 0
    for c in word:
        result += LETTER_SCORES.get(c.upper(), 0)
    return result
Exemple #8
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    sum = 0
    for c in word:
        sum += LETTER_SCORES.get(c.upper(), 0)
    return sum
Exemple #9
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    cur_sum = 0
    for ch in word.upper():
        cur_sum += LETTER_SCORES.get(ch, 0)
    return cur_sum
Exemple #10
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""

    scores = map((lambda c: LETTER_SCORES.get(c, 0)), list(word.upper()))

    return sum(scores)
Exemple #11
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    word_value = 0
    for letter in word:
        word_value += LETTER_SCORES.get(letter.upper(), 0)
    return word_value
Exemple #12
0
def calc_word_value(test_str):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    score = 0
    for letter in test_str:
        if letter not in [".",",","-","_",":",";"]:
            score += LETTER_SCORES.get(letter.upper())
    return score
Exemple #13
0
def calc_word_value(w):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    word = list(w.upper())
    counter = 0
    for letter in word:
        counter += LETTER_SCORES.get(letter, 0)
    return counter
Exemple #14
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    value = 0

    value = sum(LETTER_SCORES.get(char.upper(), 0)
                for char in word)  # dict.get return 0 if key value not found.
    return value
Exemple #15
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    total = 0
    for char in word.upper():
        total += LETTER_SCORES.get(char, 0)

    return total
Exemple #16
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    sum = 0
    for c in list(word):
        score = LETTER_SCORES.get(c.upper())
        if score:
            sum += score
    return sum
Exemple #17
0
def calc_word_value(word):
    """
    Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES
    """
    return reduce(
        lambda accum, char: accum + LETTER_SCORES.get(char.upper(), 0),
        list(word), 0
    )
Exemple #18
0
def calc_word_value2(word):
    """
    Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES
    """
    result: int = 0
    for letter in word.upper():
        result += LETTER_SCORES.get(letter, 0)
    return result
Exemple #19
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    word_value = 0
    for s in word:
        s = s.upper()
        if s.isalpha():
            word_value = word_value + int(LETTER_SCORES.get(s))

    return word_value
Exemple #20
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    score = 0
    word = word.upper()
    for letter in word:
        my_score = LETTER_SCORES.get(letter) # Handles if there are non alphabetic letters
        if my_score:
            score += my_score
    return score
def calc_word_value(word):
    """
	:param word: A single word string containing only alphabet characters
	Calculate the value of the word entered into function
	using imported constant mapping LETTER_SCORES
	"""
    # "For each letter in word, join it back together if the letter is an
    # alphabetical character"
    word = ''.join(letter for letter in word.upper() if letter.isalpha())

    # "Sum letter values for each letter in the word."
    score = sum(LETTER_SCORES.get(letter) for letter in list(word))
    return score
Exemple #22
0
def calc_word_value(word):
    letters = []
    value = []
    for letter in word:
        letters.append(letter)

    for char in LETTER_SCORES:
        for letter in letters:
            if letter.lower() == char.lower():
                value.append(LETTER_SCORES.get(char))
        else:
            pass
    
    score = sum(value)
    return score
Exemple #23
0
def calc_word_value(word, return_word=False):
    """
    Calculates the value of the word entered into function using imported
    constant mapping LETTER_SCORES. Optionally returns the word itself, too.
    """
    # using get function on the dictionary to yield a default value of 0 if
    # current character is not among the dictionary's keys
    word_value = sum(LETTER_SCORES.get(char, 0) for char in word.upper())

    # returning only the word value by default
    if not return_word:
        return word_value
    # otherwise returning word and word value
    else:
        return word, word_value
Exemple #24
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""

    word = word.upper()

    try:
        return word_values[word]
    except KeyError:
        value = 0
        for letter in word:
            value += LETTER_SCORES.get(letter, 0)
        word_values[word] = value

        return value
Exemple #25
0
def calc_word_value(word):
    """Calc a given word value based on Scrabble LETTER_SCORES mapping"""
    return sum(LETTER_SCORES.get(char.upper(), 0) for char in word)
Exemple #26
0
def calc_word_value(word):
    sum = 0
    for j in word:
        sum = sum + (LETTER_SCORES.get(j.upper(), 0))
    return sum
Exemple #27
0
def calc_word_value(word):
    finish_count = 0
    for k in list(word):
        count_word = LETTER_SCORES.get(k.upper(), 0)
        finish_count += count_word
    return finish_count
Exemple #28
0
def calc_word_value(w):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    return sum((LETTER_SCORES.get(c.upper(),0) for c in w))
Exemple #29
0
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    return reduce(lambda total, char: total + LETTER_SCORES.get(char, 0), word,
                  0)
def calc_word_value(word):
    """Calculate the value of the word entered into function
    using imported constant mapping LETTER_SCORES"""
    word_score = sum([LETTER_SCORES.get(letter, 0) for letter in word.upper()])
    return word_score
Exemple #31
0
def calc_word_value(word):
    """Calc a given word value based on Scrabble LETTER_SCORES mapping"""
    return sum(LETTER_SCORES.get(char.upper(), 0) for char in word)
Exemple #32
0
def calc_word_value(word):
    return sum(LETTER_SCORES.get(char.upper(), 0) for char in word)