cadDictionary = {'wma': 'white male adult', 'bma': 'black male adult', 'subj':'subject', 'ama':'asian male adult', 'dot': 'direction of travel', 'er':'enroute', 'citz':'citizen', '413':'handgun'\ ,'bld':'build', 'blk':'black', 'pr':'person reporting', 'sil':'silver', 'atl':'attempt to locate', 'll':'landlined', 'ofcrs':'officers', 'vict':'victim', 'neg':'negative'\ ,'ar': 'arrived', 'arr':'arrived', 'hrs':'hours', 'pr\'s':'person reportings', 'ne':'northeast', 'se':'southeast', 'nw':'northwest', 'sw':'southwest', 'req':'request',\ 'thn':'thin', 'avail':'available', 'frm':'from', 'nfd':'no further description', 'rec':'re-call', 'ls':'last seen', 'sb':'southbound', 'nb':'northbound', 'wb':'westbound',\ 'eb':'eastbound', 'stby':'standby', 'ifo':'in front of', 'blu':'blue', 'grn':'green', 'apt':'apartment', 'apts':'apartments', 'thru':'through', 'w/':'with', 'med':'medical',\ 'refd':'refused', 'ref\'d':'refused', 'info':'information', 'nfi':'no further information', 'susp':'suspect', 'vic':'victim', 'unk':'unknown', 'tl':'time lapse', \ 'prev':'previous', 'addr':'address', 'res':'residence', 'rpt':'report', 'ref':'reference', 'whi':'white', 'plot':'parking lot', 'rets':'returns'} ##Converts a sentence into a list of words (also converts all words in sentence to lower case)(based on spaces) def convertStringToList(newString): words = [] newWord = '' for i in range(len(newString)): if newString[i] != ' ' and i+1 != len(newString): newWord = newWord + newString[i].lower() elif i+1 == len(newString) and newString[i] != ' ': newWord = newWord + newString[i].lower() words.append(newWord) newWord = '' else: words.append(newWord) newWord = '' return words print words ##translates an individual word based on a dictionary key -> value def translate(word): return cadDictionary.get(word, word) ##runs the translate function for each word in the sentence def sentenceTranslate(sentence): translation = '' for i in sentence: if translation != '': translation = translation + ' ' + translate(i) else: translation = translate(i) return translation sentence = str(raw_input("Enter the Sentence: ")) ##sentence = 'hello my ama friends bma' sentence = convertStringToList(sentence) print sentenceTranslate(sentence)
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question