#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
>>2
If that's the most significant problem you see with that code, you should probably return to /pr/.
Name:
Anonymous2010-06-27 1:01
>>3
You have no basis to make that comment, as this is excellent code and works perfectly. Many students and serious programmers will find it useful in their work. I used anagrams when I was studying Mathematics, which I gained an International Baccalaureate in 1987, and Mathematics was invented by the Muslim al-Khwarizmi.
Name:
Anonymous2010-06-27 1:43
>>4 implying that an International Baccalaureate is significant
>>14
What's up with this "pretend /prog/ was better ere summer" meme, now? It has been worse than ever through most of the year. Just like last year, and the year before that.
>>15
What's up with this ``"pretend /prog/ was better ere summer" meme'' meme, now? It has been worse than ever through most of the year. Just like last year, and the year before that.
Name:
Anonymous2010-06-27 23:26
pretend /prog/ was better ere summer is an anagram of entrapped remember rewrote gusts
>>16
What's up with this 66What's up with this ``"pretend /prog/ was better ere summer" meme'' meme, now? It has been worse than ever through most of the year. Just like last year, and the year before that.99 meme, now? It has been worse than ever through most of the year. Just like last year, and the year before that.
i am a heron. i haev a long neck and i pick fish out of the water w/ my beak. if you dont repost this comment on 10 other pages i will fly into your kitchen tonight and make a mess of your pots and pans