Welcome, guest | Sign In | My Account | Store | Cart

An anagram could be a word, or a sentence, of which the letters could be rearranged to form a different word, or a different sentence.

However, vowels and consonants could be combined to form a syllable.

Though, counting the numbers of vowels and consonants forming a word or a phrase, is a writing technique to enhance the writing style, and balance the phonetic.

My program Anagrams, vowels, and consonants, allows you to compute the numbers of vowels, and consonants forming a word, a sentence, or a full text, and rearrange the letters forming every word within a text in every possible combination, thus, finding anagrams for each word within the sentence.

Python, 264 lines
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
#On the name of ALLAH and may the blessing and peace of Allah 
#be upon the Messenger of Allah Mohamed Salla Allahu Aliahi Wassalam.
#Author : Fouad Teniou
#Date : 15/06/10
#version :2.6

from string import *
from itertools import *

"""
My program uses special functions to test, count, and extract vowels and consonants.
However,the string_check function uses isinstance() to check an objects type
and isinstance(obj, str) will be True only if obj is a str, and the 
vowel_or_Consonant is a boolean function that accept a text(string)as
an argument and which return either True or False and which you can call in
the program at any time to test every letter within a string to
determine whether it is a vowel or consonant.
Though, Vowel and Consonant functions return the count of each vowel and consonant.
and Anagrams_search function return a set of every possible combination,thus,
every possible Anagram.

"""

def my_try(arg =''):
    """ Raises an error exception if a letter is not in the alphabet or if the letter is not a space character ."""

    for item in arg:
        if item not in 'abcdefghijklmnopqrstuvwxyz ':
            raise TypeError,\
                "\n<Every letter within the text should be in the alphabet. \n"

def string_check(function):
    """
    A function which uses isinstance to determine whether an object is a string.
    """
    
    def wrapper(character):
        # string_check raises assertionError
        # if the character is not a string
        assert isinstance(character, str),\
        "Please enter a string and not %s" % (character)
        return function(character)
    return wrapper 
    
def Vowel_or_Consonant(char = ''):
    """
    A boolean function, which return either True or False
    """

    # Determine whether each letter in the text is a vowel or a
    # consonant. if it is a vowel, set test to True, otherwise, set test to false.
    for i in char:
        if str(i)in 'aeiouy':
            test = True
        else :
            test = False
        # Return the value of the test variable    
        return test
        
@string_check    
def Vowel(text = ''):
    """
    A function which return a set of vowels and the total
    number of each vowel in the text. 
    """
    
    #empty string
    string_A = ''
    for item in lower(text):
        if Vowel_or_Consonant(str(item)):
            string_A += item
            
    # sort a string_A
    char_A = sorted(string_A)
    
    # vowels' counts
    return "\n<The vowels are : %s \n" % \
           [(arg, len(list(karg))) for arg, karg  in groupby(char_A)]

@string_check           
def Consonant(text = ''):
    """
    A function which return a set of consonants and the total
    number of each consonant in the text. 
    """
    
    string_B = ''
    string_C = ''
    for arg in lower(text):
        if not Vowel_or_Consonant(str(arg)) and str(arg) in 'bcdfghjklmnpqrstvwxz':
            string_B += arg
        elif not Vowel_or_Consonant(str(arg)) and str(arg) not in 'bcdfghjklmnpqrstvwxz':
            string_C += arg
    # sort a string_B
    char_B = sorted(string_B)
    char_C = sorted(string_C)
    # consonants and others characters' Counts
    return "<The consonants are :%s \n\n<And the others characters are : %s\n" % \
           ([(arg, len(list(karg))) for arg, karg in groupby(char_B)],\
            [(arg, len(list(karg))) for arg, karg in groupby(char_C)])

def Anagrams_search(phrase = ''):
    """
    A function which return a set of every combination possible and for
    every word within a text.
    """
    #empty list
    mylist = []
    try:
        my_try(lower(phrase))
        
        for word in list(split(phrase)):
            #every possible combination for each word within the text 
            split_list = [arg for arg in permutations(lower(word),len(word))]
    
            for item in split_list:
                split_list = join(item,'')
                #append mylist 
                mylist.append(split_list)
        # a list of every possible combination including anagrams
        return "<The list of every possible combination and anagrams : %s" % \
               mylist
    #The program raise TypeError if input is not in the alphabet
    except TypeError,exception :
        print exception

if __name__ == "__main__":
  

    vowels = Vowel('Fouad Teniou')
    print vowels
    consonants = Consonant('Fouad Teniou')
    print consonants
    anagrams = Anagrams_search('Ten iou')
    print anagrams
    anagrams1 = Anagrams_search('Ten i7u')
    print anagrams1

#######################################################################

#python "C:\PythonPrograms\Anagrams-vowels-consonants.py"

#<The vowels are : [('a', 1), ('e', 1), ('i', 1), ('o', 2), ('u', 2)]

#<The consonants are :[('d', 1), ('f', 1), ('n', 1), ('t', 1)]

#<And the others characters are : [(' ', 1)].

#<The list of every possible combination and anagrams : 
#['ten', 'tne', 'etn', 'ent', 'nte', 'net', 'iou', 'iuo', 'oiu', 'oui', 'uio', 'uoi']

#<Every letter within the text should be in the alphabet.

#######################################################################
#VERSION PYTHON 3.2

#from itertools import *


#def my_try(arg =''):
#    """ Raises NegativeNumberError if number less than 0, and
#    raises ZeroNumberException if number is equal to 0."""
#    for item in arg:
#        if item not in 'abcdefghijklmnopqrstuvwxyz ':
#            raise TypeError("\n<Every letter within the text should be in the alphabet #\n")
#
#def string_check(function):
#    """
#   A function which uses isinstance to determine whether an object is a string.
#    """
#    
#    def wrapper(character):
#        # string_check raises assertionError
#        # if the character is not a string
#        assert isinstance(character, str),\
#        "Please enter a string and not %s" % (character)
#        return function(character)
#    return wrapper 
#    
#def Vowel_or_Consonant(char = ''):
#    """
#    A boolean function, which return either True or False
#    """
#
#    # Determine whether each letter in the text is a vowel or a
#    # consonant. if it is a vowel, set test to True, otherwise, set test to false.
#    for i in char:
#        if str(i)in 'aeiouy':
#            test = True
#        else :
#            test = False
#        # Return the value of the test variable    
#        return test
#        
#@string_check    
#def Vowel(text = ''):
#    """
#    A function which return a set of vowels and the total
#    number of each vowel in the text. 
#    """
#    
#   #empty string
#    string_A = ''
#    for item in str.lower(text):
#        if Vowel_or_Consonant(str(item)):
#            string_A += item
#            
#    # sort a string_A
#    char_A = sorted(string_A)
#    
#    # vowels' counts
#    return "\n<The vowels are : %s \n" % \
#           [(arg, len(list(karg))) for arg, karg  in groupby(char_A)]#
#
#@string_check           
#def Consonant(text = ''):
#    """
#    A function which return a set of consonants and the total
#    number of each consonant in the text. 
#    """
#    
#    string_B = ''
#    string_C = ''
#    for arg in str.lower(text):
#        if not Vowel_or_Consonant(str(arg)) and str(arg) in 'bcdfghjklmnpqrstvwxz':
#            string_B += arg
#        elif not Vowel_or_Consonant(str(arg)) and str(arg) not in 'bcdfghjklmnpqrstvwxz':
#            string_C += arg
#    # sort a string_B
#    char_B = sorted(string_B)
#    char_C = sorted(string_C)
#    # consonants and others characters' Counts
#    return "<The consonants are :%s \n\n<And the others characters are : %s\n" % \
#           ([(arg, len(list(karg))) for arg, karg in groupby(char_B)],\
#            [(arg, len(list(karg))) for arg, karg in groupby(char_C)])
#
#def Anagrams_search(phrase = ''):
#    """
#    A function which return set of every combination possible and for
#    every word within a text.
#    """
#    #empty list
#    mylist = []
#    try:
#        my_try(str.lower(phrase))
#        
#        for word in list(str.split(phrase)):
#            #every possible combination for each word within the text 
#            split_list = [arg for arg in permutations(str.lower(word),len(word))]
#           
#            for item in split_list:
#                
#                    
#                    split_list = ''.join(item)
#                    #append mylist
#                    
#                    mylist.append(split_list)
#        # a list of every possible combination including anagrams
#        return "<The list of every possible combination and anagrams : %s" % \
#               mylist
#    #The program raise TypeError if input is not in the alphabet
#    except TypeError as exception :
#        print(exception)
#

1 comment

Fouad Teniou (author) 12 years, 8 months ago  # | flag

A switch to C# and a new link

http://archive.msdn.microsoft.com/fouadteniou