Ejemplo n.º 1
0
 def wordLetters(S, Rack, n):
     """Takes inputs of a string "S" and the letters in "Rack", as well as a variable n, and returns Boolean True, 
     if the letters from Rack match S up to S[n]. It makes sure there are enough letters in Rack to form string S."""
     if n == len(S): return True
     if S[n] in Rack:
         if len(filter(lambda x: S[n] == x, S)) <= len(
                 filter(lambda x: S[n] == x, Rack)):
             return True and wordLetters(S, Rack, n + 1)
         else:
             return False
Ejemplo n.º 2
0
def prime(n):
    """
    Returns whether or not the integer is prime
    """
    possible_divisors = range(2, int(math.sqrt(n)))
    divisors = filter(lambda x: n % x == 0, possible_divisors)
    return len(divisors) == 0
Ejemplo n.º 3
0
def getWords(Rack):
    """
    Returns a list of all the words that can be made from the given Rack.
     
    Inputs: Rack list of lowercase letters
    """
    return filter(lambda x: exists(x, Rack), Dictionary)
def scoreList(Rack):
    '''score list takes the list of strings and prints out the possible words from that list'''
    def count(letter, lst):
        '''helper function that counts the amount of letters in the word(lst). '''
        if lst == '' or lst == []:
            return 0
        if letter == lst[0]:
            return count(letter, lst[1:]) + 1
            '''using the recursive the function returns the count plus 1 if the first letter is equal to the first element in the lst.'''
        return count(letter, lst[1:])
        '''if not it returns the recursive of the rest of the elements in the lst.'''

    def canSpell(rack, word):
        '''helper function to see if we can spell the word, so we need a rack of  letters but just need to find a word within that rack.'''
        if word == '':
            return True
        if count(word[0], word) > count(word[0], rack):
            return False
            '''if the count of the characters in the word is greater than that of the count letters in the rack then the return is false.'''
        return canSpell(rack, word[1:])
        '''if not then use the recursive to find the spelling of the word in the rack'''

    lst = filter(lambda word: canSpell(Rack, word), Dictionary)
    '''lst = use the filter function to to check if the rack of letters can form a word so that it correlates to the dictionary'''
    return map(lambda word: [word, wordScore(word, scrabbleScores)], lst)
    '''map goes through the words in the dictionary and makes a new list and fills it in with the word and the score of the word for all of the Rack input.  the lst will help correlate the words and letters to the dictionary '''
Ejemplo n.º 5
0
def findBestUser():
    '''Returns the user(s) whose artist preferences are most
    similar to the current user without being exactly the same'''
    global NAME
    global ARTISTS
    global DATABASE
    names=DATABASE
    names=filter(lambda x: x[-1] != '$', names)
    if len(DATABASE)==1:
        print ("No Recommendations available at this time")
        menu()
    else:
        greatest_count=0
        greatest_user = []
        for username in names:
            if DATABASE[username] != DATABASE[NAME]:
                count= numMatches(DATABASE[username],DATABASE[NAME])
                if count>greatest_count:
                    greatest_user.clear()
                    greatest_count=count
                    greatest_user.append(username)
                elif count==greatest_count:
                    greatest_count=count
                    greatest_user.append(username)
        return (greatest_user)
Ejemplo n.º 6
0
def scoreList(Rack):
    """Takes an input of a "Rack" of letters and finds which words can be produced from Dictionary, 
    and also returns the points for each word."""
    def wordLetters(S, Rack, n):
        """Takes inputs of a string "S" and the letters in "Rack", as well as a variable n, and returns Boolean True, 
        if the letters from Rack match S up to S[n]. It makes sure there are enough letters in Rack to form string S."""
        if n == len(S): return True
        if S[n] in Rack:
            if len(filter(lambda x: S[n] == x, S)) <= len(
                    filter(lambda x: S[n] == x, Rack)):
                return True and wordLetters(S, Rack, n + 1)
            else:
                return False

    def wordChecker(Rack):
        """Takes an input of a "Rack" of letters and returns a list of words that can be formed"""
        def wordCheckerHelper(S):
            if (lambda x: x in Rack, S):
                if wordLetters(S, Rack, 0):
                    return [S] + [wordScore(S, scrabbleScores)]
                else:
                    return []
            else:
                return []

        return wordCheckerHelper

    return filter(lambda a: a != [], map(wordChecker(Rack), Dictionary))
Ejemplo n.º 7
0
def prime(n):
    """return whether or not an integer is prime"""
    possible_divisors = range(2, int(math.sqrt(n)))
    divisors = filter(lambda x: n % x == 0, possible_divisors)
    if (divisors == []):
        return True
    return len(divisors) == 0
Ejemplo n.º 8
0
def scoreList(Rack):
    """Creates a list of the words that can be made from the Rack"""
    def score(lst):
        if lst == []:
            return []
        return [wordScoreCombo(lst[0], scrabbleScores)] + score(lst[1:])

    return score(filter(lambda x: x != '', getList(Rack, Dictionary)))
def keep_integers_filter(lst):
    '''Assume lst is a list of all different data types. There could be ints,
    floats, strings, booleans, nested lists, and more.
    Return a list of only the integers present in the original list. You do
    not have to worry about integers inside nested lists and can safely
    ignore them.
    You may use type(data) == int to determine if the data variable is an
    integer.
    This part is worth 10 points.'''
    return filter(lambda x: type(x) == int, lst)
Ejemplo n.º 10
0
 def makeWord(n, w):
     if n == []:
         return []
     if w == []:
         return []
     y = len(filter(lambda x: x == w[0], n))
     if 0 < y and y <= len(w):
         n.remove(w[0])
         return ([w[0]] + makeWord(n, w[1:]))
     return []
Ejemplo n.º 11
0
def scoreList(rack):
    """Takes a rack of letters as input and returns the 
    different words you could play and their corresponding scores."""
    possiblewords = filter(lambda x: wordinrack(rack, x),
                           Dictionary)  #creates list of possible words

    def output(lst):
        if lst == []:  #Function that formats output
            return []
        return [[lst[0], wordScore(lst[0], scrabbleScores)]] + output(lst[1:])

    return output(possiblewords)
Ejemplo n.º 12
0
def filter_names(name_length_pairs, min_length):
    '''Returns a list of all [name, length] pairs where the length field is
    >= min_length.

    For instance, assuming list_of names starts off as the list in line 10 and
    min_length is 5, the list returned by this function will
    include only [['Barry', 5], ['Christine', 9], ['Frank', 5]].

    lambda takes in a single pair from name_length_pairs, for example,
    ['Abe', 3].
      - pair[0] is 'Abe'
      - pair[1] is 3'''
    return filter(lambda pair: pair[1] >= min_length, name_length_pairs)
Ejemplo n.º 13
0
 def sieve(lst):
     if lst == []:
         return []
     return [lst[0]] + sieve(filter(lambda x: x % lst[0] != 0, lst[1:]))
Ejemplo n.º 14
0
def letterScore(letter, scorelist):
    '''Returns a number that is associated with a letter'''
    result = filter((lambda x: x[0] == letter), scorelist)
    return result[0][1]
Ejemplo n.º 15
0
def prime(n):
    '''returns whether or not an integer is prime'''
    possible_divors = range(2, int(math.sqrt(n)) + 1)
    divors = filter(lambda x: n % x == 0, possible_divors)
    return len(divors) == 0
Ejemplo n.º 16
0
Archivo: hw2.py Proyecto: cs-paz/CS-115
def letterScore(letter, scorelist):  #returns score associated with that letter
    if (scorelist[0][0] == letter):
        return scorelist[0][1]
    else:
        return filter(lambda x: x[0] == letter, scorelist)[0][1]
Ejemplo n.º 17
0
def list_of_word_created(dictionary, letters):
    '''returns a list of the words that are possible from given letters'''
    return filter(lambda word: is_word_possible(word, letters), dictionary)
Ejemplo n.º 18
0
def prime(n):
    '''Returns True if n is prime and False otherwise by testing all possible divisors from 2 to n-1 or sqrt of n.'''
    possible_divisors = range(2, int(math.sqrt(n)) + 1)
    divisors = filter(lambda x: n % x == 0, possible_divisors)
    return len(divisors) == 0
Ejemplo n.º 19
0
Archivo: hw2.py Proyecto: hamc24/Intro
def availableWords(Rack):
    '''returns a list of words in the dictionary that can created using Rack'''
    return filter(lambda S: wordCheck(S, Rack), Dictionary)
Ejemplo n.º 20
0
def scoreList(rack):
    '''Returns the list of all possible words and their scores based on the given rack'''
    return combine(
        filter(poss(rack),
               Dictionary))  #Filters the possible words then combines them
Ejemplo n.º 21
0
        if lst == []:
            return accum
        return my_reduce_helper(f, lst[1:], f(accum, lst[0]))

    if lst == []:
        raise TypeError('my_reduce() of empty sequence with no initial value')
    return my_reduce_helper(f, lst[1:], lst[0])


"""
def end3(x):
    return x % 10 == 3 
eliminated by lambda 

"""
print(filter(lambda x: x % 10 == 3, [3, 33, 243, 24]))
print(my_map(lambda x: x * x, [1, 2, 3, 4]))


def prime(n):
    """takes an integer n and tells whether or not it is prime"""
    possible_divisors = range(2, int(math.sqrt(n)) + 1)
    divisor = filter(lambda x: n % x == 0, possible_divisors)
    return len(divisor) == 0


def primes(n):
    """Takes an integer n finds all primes less than or equal to some given n """
    def sieve(lst):
        if lst == []:
            return []
Ejemplo n.º 22
0
def list_of_codes_created(dictionary, numbers):
    """Runs through the string of words using the filter, and puts the words into a list"""
    return filter(lambda code: is_code_possible(code, numbers),dictionary)
Ejemplo n.º 23
0
def list_of_words_created(Dictionary, letters):
    ''' creates a  list of possible words'''
    return filter(lambda word: is_word_possible(word, letters), Dictionary)
Ejemplo n.º 24
0
def prime(n):
    """returns wether or not an integer is prime"""
    possibleDivisors = range(2, int(math.sqrt(n)) + 1)
    divisors = filter(lambda X: n % X == 0, possibleDivisors)
    return len(divisors) == 0
Ejemplo n.º 25
0
def list_of_words(Dictionary, rack): 
    """Takes in a list of letters returns only the combinations that make words"""
    return filter(lambda word: isPossible(word, rack), Dictionary)
Ejemplo n.º 26
0
def list_of_possible_words(dictionary, rack):
    return filter(lambda word: is_word_possible(word, rack), dictionary)
Ejemplo n.º 27
0
def allWordsFromLetters(letters, Dict):
    '''returns a list of all possible words in Dict that can be made from the list of letters, letters'''
    return filter(lambda seq: canStringBeMade(seq, letters), Dict)
Ejemplo n.º 28
0
def prime(n):
    """takes an integer n and tells whether or not it is prime"""
    possible_divisors = range(2, int(math.sqrt(n)) + 1)
    divisor = filter(lambda x: n % x == 0, possible_divisors)
    return len(divisor) == 0
Ejemplo n.º 29
0
def isInDict(w, D):
    """Checks if a word is in the dictionary"""
    if D == []:
        return 'invalid'
    return filter(lambda x: x == w, D)
Ejemplo n.º 30
0
def listOfWords(Dictionary, Rack):
    """this will take in a rack and dictionary as input and return the list of words and their values possible with the given Rack"""
    return filter(lambda word: isPossible(word, Rack), Dictionary)