Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Anagrams

Name: Fouad Teniou 2010-06-26 22:15

#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.

Name: Anonymous 2010-06-26 22:23

one word

Name: Anonymous 2010-06-26 22:27

>>2
If that's the most significant problem you see with that code, you should probably return to /pr/.

Name: Anonymous 2010-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: Anonymous 2010-06-27 1:43

>>4
implying that an International Baccalaureate is significant

Name: Anonymous 2010-06-27 2:00

>>5
Back to the imageboards, please.

Name: Anonymous 2010-06-27 3:27

>>6
implying that saying that is going to make it happen

Name: Anonymous 2010-06-27 7:59

what ALL AH you guys AND gals don't realISe the gLAMorous  wonder this code presents. compared to this, most code out there SUCKS DONKEY BALLS.

Name: Anonymous 2010-06-27 15:42

SUCKS DONKEY BALLS is an anagram of BACON DYKES SKULLS

Name: Anonymous 2010-06-27 15:44

>>8
Fuck off and die in a (hell) fire.

Name: Anonymous 2010-06-27 15:57

Fuck off and die in a (hell) fire is an anagram of If Lain offline, her deaf duck.

Name: Anonymous 2010-06-27 16:12

I'd her deaf duck, if you know what I mean.

Name: Anonymous 2010-06-27 20:33

C:/
troll harder fag

Name: Anonymous 2010-06-27 20:44

>>2,5,7-8,13
Is this what /prog/ is now? The summer wasn't this bad last year.

Name: Anonymous 2010-06-27 21:20

>>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.

Name: Anonymous 2010-06-27 22:35

>>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: Anonymous 2010-06-27 23:26

pretend /prog/ was better ere summer is an anagram of entrapped remember rewrote gusts

Name: Anonymous 2010-06-27 23:47

>>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.

Name: Anonymous 2010-06-28 1:12

EXPERT RECURSIVE MEME USERS

Name: Anonymous 2010-06-28 2:48

EXPERT RECURSIVE MEME USERS is an anagram of creepier vertexes ruses mum.

Name: Anonymous 2010-06-28 3:01

>>20
I'll be honest with you; that's not a very good anagram.

Name: Anonymous 2010-06-28 3:05

>>21
Not a very good anagram is an anagram of a moody arrogant vegan.

Name: Anonymous 2010-06-28 5:33

>>10
Why would I die in hellfire? I'm not Muslim.

"Between 2001 and 2007, the U.S. has fired over 6,000 Hellfires in combat
http://en.wikipedia.org/wiki/Hellfire_missile


YEAAAAAAHHHHHHHHH

Name: Anonymous 2010-06-28 5:35

I'm not Muslim is an anagram of Mini Slut Mom

Name: Anonymous 2010-06-28 5:38

YEAAAAAAHHHHHHHHH is an anagram of AYE, HAHHAHHAHHAHHA

Name: Anonymous 2010-06-28 5:59

is an anagram of is an anagram of As I ram anonfag

Name: Anonymous 2010-06-28 6:02

JEWS

Name: Anonymous 2010-06-28 6:02

is an anagram of is an anagram of As I ram anonfag is an anagram of foam air arson fag mania sang 'An Aria Fangs Moan'

Name: Anonymous 2010-06-28 10:34

>>26-28
Back to /b/ please.

Name: Anonymous 2010-06-28 10:38

Back to /b/ please is an anagram of Polecat Kebabs.

Name: Anonymous 2010-06-28 10:39

>>30
I'm going to start using that.

Name: Anonymous 2010-06-28 10:46

>>30
* /Polecat Kebabs/

Name: Anonymous 2010-06-28 10:51

/Polecat Kebabs/

Name: Anonymous 2010-06-28 10:52

Is it usually two sub or how is it?

/Polecat Kebabs/

Name: Anonymous 2010-06-28 11:13

>>34
{miou /Polecat Kebabs/}

Name: Anonymous 2010-06-28 11:28

{meow /Polecat Kebabs/}

Name: Anonymous 2010-06-28 12:16


def Vowel_or_Consonant(char = ''):
    """
    A boolean function, which return either True or False
    """

goddamn!

Name: Anonymous 2010-06-28 12:29

>>37
the Forced Docstringization Of the Code, thread over.

Name: Anonymous 2010-06-28 18:20

There is a man, his female friend is womanly waiting for her manly friend.

His name is /POLECAT KEBABS/.

Name: Anonymous 2010-06-29 2:00

HAX MY ANAGRAM

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List