# Solution Exercise 30: Python algorithm that determines the list of words that do not contain any digits in a given text

May 19, 2021

#### Exercise 30

Write a Python algorithm that determines the list of words containing no digits in a given T text.

#### Solution

``# creation of a function which detects if a word contains a number or notdef digitInWord (word):    counter = 0    for x in word:        if x.isdigit():            counter = counter + 1    if counter> 0:        return True    else:        return False# creation of a function which returns the list of words with no digitsdef noDigitInText (T):    # initialize the list of words with no digits    listWordWithoutNumber = []    # convert text T to a list    L = T.split ()    for word in L:        # we test if the word 'word' does not contain any digits        # using the digitInWord function defined previously        if not digitInWord(word):            listWordWithoutNumber.append (word)    return listWordWithoutNumber# ExampleT = "Python2.7 has been replaced by Python3.X since 2018"print ("the list of words with no digit is: ", noDigitInText (T))# returns: the list of words with no digit is:  ['has', 'been', 'replaced', 'by', 'since']``
Younes Derfoufi
my-courses.net