Trouble with sms to english converter

Post your questions, doubts and issues related to Python Programming
no avatar
arichards
 
Posts: 1
Joined: Wed Aug 29, 2012 8:21 pm
Location: Australia

Trouble with sms to english converter

by arichards » Wed Aug 29, 2012 8:31 pm

###Having trouble passing through words not in the dictionary. Can anyone help?

dictionary = \
[['r', 'are'],
['txt', 'text'],
['k', 'okay'],
['2moro', 'tomorrow'],
['4', 'for'],
['b', 'be'],
['ne', 'any'],
['nite', 'night'],
['b4', 'before']] #Plus lots more words in the compete dictionary

import string
import re

item = """c u r 2 wk y hello evry1 sed pix r gd""" #the word hello doesn't make it through because it's not in the dictionary but I need it to come through.

##Convert sms to english starts here...
def sms_to_english(item):
sms=[]
item_split = item.split()
for word in item_split:
for j in range(len(dictionary)):
if word == dictionary[j][0]:
sms.append(dictionary[j][1])


return " ".join(sms)

no avatar
shibenchouhan
 
Posts: 1
Joined: Wed Oct 10, 2012 7:53 pm
Location: Kolkata

by shibenchouhan » Wed Oct 10, 2012 8:05 pm

###Having trouble passing through words not in the dictionary. Can anyone help?

Code: Select all
dictionary = \
[['r', 'are'],
['txt', 'text'],
['k', 'okay'],
['2moro', 'tomorrow'],
['4', 'for'],
['b', 'be'],
['ne', 'any'],
['nite', 'night'],
['b4', 'before']] #Plus lots more words in the compete dictionary

import string
import re

item = """c u r 2 wk y hello evry1 sed pix r gd""" #the word hello doesn't make it through because it's not in the dictionary but I need it to come through.

##Convert sms to english starts here...
def sms_to_english(item):
      sms=[]
      item_split = item.split()
      for word in item_split:
           for j in range(len(dictionary)):
                if word == dictionary[j][0]:
                      sms.append(dictionary[j][1])
           sms.append(word) #this will add the hello word which are not present in dictionary as the original word.


       return " ".join(sms)

no avatar
asifsuun
 
Posts: 1
Joined: Tue Oct 16, 2012 5:58 pm

by asifsuun » Tue Oct 16, 2012 6:03 pm

I wanted to thank you for this great read!!

Return to Python Programming

cron