因此,i m试图在Python(在60个装置中)创建一名翻译。 因此,试图做的是,在不触及其他词的情况下仅用一个字。 这里的例子
Original: "The brown fox jumps over the dog named brownie." I want to replace the word "brown" into "deathlesi"(Just ignore why) The result should be: "The deathlesi fox jumps over the dog named brownie." But instead it also changes "brownie" in the string which results to: "The deathlesi fox jumps over the dog named deathlesiie."
Since I m trying to replace each and every word, sometimes it goes into a never ending paradox. Example: "I am stupid" I m trying to change "I" into "ium" and this is what happens. "iumumumumumumumumumumumumumumumumumumumum.... am stupiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuiuim..", it basically changes every "I" in the string and won t stop until there s no "I" in the string.
任何帮助? 感谢!
Edit:我已经尝试过“地圈”,但某些部分,如“一”小块,通常取代“一” st。
Here s another example: "People are getting excited at the giant hare." replacing "are" to "iume", instead of "People iume getting excited at the giant hare." it also replaced "hare" which resulted into "People iume getting excited at the giant hiume."
Supposedly I array ed the sentence and translate each of them. That is my current method now. Basically converting each word into a array and converting each one of them. Then doing a
translated_sentence=["particulus:people", "iume:are", "geus:getting", "exchantus:excited", "d:at", "qun:the", "gesas:giant", "hsont:hare"]
sentence= "People are getting excited at the giant hare."
for i in translated_sentence do
element=i.split(":")
sentence=sentence.replace(element[1], element[0])
并且仍然投下“部分ulu”
I just got it figured it out. I just splitted the string into an array, and preserved the formatting by cleaning the current word and doing a string.replace() to the original word.
sentence="The quick brown fox jumps over the lazy dog.".split(" ")
result=""
for i in sentence:
cleaned=clean(i) #removes the punctuations and stuff leaving the raw word.
translated=translate(cleaned) #returns the translated word
result=result+i.replace(cleaned,translated)+" "
return result