Skip to main content
added 223 characters in body
Source Link
Marc
  • 5.7k
  • 2
  • 15
  • 35

Any help will be appreciated

A few suggestions on something that I noticed:

  • In the function makechain the else after the return is not necessary.

  • Typo in: VOWELS = set('aeiouy'), there is an extra y.

  • This part:

    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy''aeiou')
    CONSONANTS = LETTERS - VOWELS
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
         ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        if type(v) == set:
            v = ''.join(sorted(v))
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    seems to do the following:

    1. Create a dictionary with mixed value's type (strings and sets)
    2. Convert all values to string
    3. Sort dictionary's values

    It could be simplified to:

    1. Create a dictionary where all values are strings
    2. Sort dictionary's values

    Additionally, having VOWELS as a set and CONSONANTS as a string is a bit confusing. Would be better to use only one type.

    Code with suggestions above:

    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy')'aeiou'
    CONSONANTS = ''.join(set(LETTERS) - set(VOWELS))
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
        ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        tails.update({i: ''.join(sorted('aeiou'VOWELS + v))})
    

    In this way, you also avoid to sortsorting twice.

Any help will be appreciated

A few suggestions on something that I noticed:

  • In the function makechain the else after the return is not necessary.

  • This part:

    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy')
    CONSONANTS = LETTERS - VOWELS
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
         ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        if type(v) == set:
            v = ''.join(sorted(v))
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    seems to do the following:

    1. Create a dictionary with mixed value's type (strings and sets)
    2. Convert all values to string
    3. Sort dictionary's values

    It could be simplified to:

    1. Create a dictionary where all values are strings
    2. Sort dictionary's values
    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy')
    CONSONANTS = ''.join(LETTERS - VOWELS)
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
        ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    In this way you also avoid to sort twice.

Any help will be appreciated

A few suggestions on something that I noticed:

  • In the function makechain the else after the return is not necessary.

  • Typo in: VOWELS = set('aeiouy'), there is an extra y.

  • This part:

    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiou')
    CONSONANTS = LETTERS - VOWELS
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
         ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        if type(v) == set:
            v = ''.join(sorted(v))
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    seems to do the following:

    1. Create a dictionary with mixed value's type (strings and sets)
    2. Convert all values to string
    3. Sort dictionary's values

    It could be simplified to:

    1. Create a dictionary where all values are strings
    2. Sort dictionary's values

    Additionally, having VOWELS as a set and CONSONANTS as a string is a bit confusing. Would be better to use only one type.

    Code with suggestions above:

    LETTERS = ascii_lowercase
    VOWELS = 'aeiou'
    CONSONANTS = ''.join(set(LETTERS) - set(VOWELS))
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
        ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        tails.update({i: ''.join(sorted(VOWELS + v))})
    

    In this way, you also avoid sorting twice.

Source Link
Marc
  • 5.7k
  • 2
  • 15
  • 35

Any help will be appreciated

A few suggestions on something that I noticed:

  • In the function makechain the else after the return is not necessary.

  • This part:

    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy')
    CONSONANTS = LETTERS - VOWELS
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
         ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        if type(v) == set:
            v = ''.join(sorted(v))
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    seems to do the following:

    1. Create a dictionary with mixed value's type (strings and sets)
    2. Convert all values to string
    3. Sort dictionary's values

    It could be simplified to:

    1. Create a dictionary where all values are strings
    2. Sort dictionary's values
    LETTERS = set(ascii_lowercase)
    VOWELS = set('aeiouy')
    CONSONANTS = ''.join(LETTERS - VOWELS)
    
    BASETAILS = {
        'a': CONSONANTS,
        'b': 'bjlr',
        'c': 'chjklr',
        'd': 'dgjw',
        ....
        }
    
    tails = dict()
    
    for i in ascii_lowercase:
        v = BASETAILS[i]
        tails.update({i: ''.join(sorted('aeiou' + v))})
    

    In this way you also avoid to sort twice.