![]() |
|
|
|
Thread Tools | Display Modes |
|
|
|
|
#1 |
|
Programmer
Join Date: May 2005
Posts: 41
Rep Power: 0
![]() |
PigLattin Converter, count number of words used in dictionary.
Ok, tried for a descriptive title. Anyways, I am having some troubles with my homework...
[PHP] # Assignment 5 translate a set of strings into piglatting based strings # It does so by moving leading consonants to the end of the word # and appending "ay" to the end. (If there are no leading consonants, # then "shay" is appended.) #Global Variables, hey if I had a pointer, I'd store these in a 3d array and return all my info in a pointer.-- store = [] storen = [] stores = [] #Function String Breakup ------------------------------------------------------ def strbrk(word, ssize): tstr = "" subcount = 0 proper = "?.,';/>< \=+-_()!~`@#$%^&*[]{}" #This here code belongs to the daily wtf.counter = 0 #$store stores the letter, $storen stores the word it's in, and stores stores what part the non alpha is in.-- while counter <= (ssize-1) : subcount = 0 for letter in word[counter] : if letter in proper : store.insert(counter, letter) storen.insert(counter, counter) stores.insert(counter, subcount) subcount+=1 counter+=1 size=len(store) counter = 0 #Takes the symbols out of the words. Will need these later for reconstruction. if(size > 0): while(counter <= size-1): for letter in word[storen[counter]]: if(letter in proper) : subcount =0 else : tstr+=letter word[storen[counter]]= tstr.lower() tstr="" counter+=1 return word #Function PigLatin--------------------------------------------------------- def piglatin(ssize, word): vowels = "aeiou" tstr ="" counter = 0 while(counter <= ssize-1): for letter in word[counter]: tstr+=letter if tstr[0] in vowels : tstr = tstr + "sh" else : tstr = tstr[1:] + tstr[0] vowels = vowels + "y" while not(tstr[0] in vowels) : tstr = tstr[1:] + tstr[0] tstr+="ay" word[counter]=tstr counter+=1 tstr="" return word #Function Translated Output------------------------------------------------- def toutput(pigword, ssize): subcount = 0 counter = 0 size = len(storen) print "\nTranslated sentence:" while(counter<=size-1) : pigword[storen[counter]]+= store[counter] counter+=1 counter = 0 while(counter<=ssize-1): print pigword[counter], counter +=1 #void main(int argc, char** argv[], char** env[]) // ---------------------name = { } subcount = 0 storec = [] counter = 0 #words2 = raw_input("Please type a line of English words: ") words2 = "This is it, is it? It is, indeed, it!!" word = words2.split() ssize = len(word) while counter < ssize : word[counter] = word[counter].lower() counter+=1 word = strbrk(word, ssize) pigword = piglatin(ssize, word) #Stuffs----------------------------------------------------- counter = 0 while(counter < ssize): for letter in pigword[counter]: name[pigword[counter]]=0 counter+=1 counter = 0 size3=len(name) while (counter < ssize) : while(subcount < ssize): if pigword[counter] == pigword[subcount]: t+=1 name[pigword[counter]] = t subcount+=1 t=0 counter +=1 #End Stuffs----------------------------------------------------- toutput(pigword, ssize) print "\n\nContents of pig-latin dictionary:" print name raw_input("\nPress Enter to quit") [/PHP] Perticularly in the "Stuffs" block. What I am attempting to do is count how many times a single word is used (such as "is" is used 3 times). I just cannot, for the life of me, figure out how to run a recursive array and get that information out. Output looks like this: Translated sentence:
isthay isshay itshay, isshay itshay? itshay isshay, indeedshay, itshay!!
Contents of pig-latin dictionary:
{'isthay': 1, 'isshay': 0, 'itshay': 0, 'indeedshay': 0}Type a line of English: This is it, is it? It is, indeed, it!! Translated sentence: isthay isshay itshay, isshay itshay? itshay isshay, indeedshay, itshay!! Contents of pig-latin dictionary: indeed : indeedshay 1 is : isshay 3 it : itshay 4 this : isthay 1 Type Enter to finish. Also, that is my test string, it just made it easier for testing. |
|
|
|
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|