473,396 Members | 1,895 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Comparing words with the words in dictionary and getting the corresponding values?

8
How do I compare words of sentences with a dictionary and get it's corresponding value.

e.g, This is the dictionary format.

WORD Pronunciation

try t-r-y-0|
test t-e-s-t-0|

Sentence list:
I try my best.
The knowledge test.

So for each word in the sentence must do dictionary lookup and get the it's corresponding values (i.e, pronunciation) and print them sentence wise. I would be grateful for the help.
Jan 13 '10 #1

✓ answered by dechen

Spot on! Thank you very much bvdet . Dictionary look up will be easier from now on. Thanks again.

2 1579
bvdet
2,851 Expert Mod 2GB
One word: dictionary
Expand|Select|Wrap|Line Numbers
  1. >>> dd = {'try': 't-r-y-0|', 'test': 't-e-s-t-0|'}
  2. >>> for word in "I try my best on each test".split():
  3. ...     v = dd.get(word, None)
  4. ...     if v:
  5. ...         print v
  6. ...         
  7. t-r-y-0|
  8. t-e-s-t-0|
  9. >>> 
Jan 13 '10 #2
dechen
8
Spot on! Thank you very much bvdet . Dictionary look up will be easier from now on. Thanks again.
Jan 18 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

125
by: Raymond Hettinger | last post by:
I would like to get everyone's thoughts on two new dictionary methods: def count(self, value, qty=1): try: self += qty except KeyError: self = qty def appendlist(self, key, *values): try:
41
by: Odd-R. | last post by:
I have to lists, A and B, that may, or may not be equal. If they are not identical, I want the output to be three new lists, X,Y and Z where X has all the elements that are in A, but not in B, and...
19
by: Dennis | last post by:
I have a public variable in a class of type color declared as follows: public mycolor as color = color.Empty I want to check to see if the user has specified a color like; if mycolor =...
1
by: john wright | last post by:
I have a dictionary oject I created and I want to bind a listbox to it. I am including the code for the dictionary object. Here is the error I am getting: "System.Exception: Complex...
19
by: Ole Nielsby | last post by:
How does the GetHashCode() of an array object behave? Does it combine the GetHashCode() of its elements, or does it create a sync block for the object? I want to use readonly arrays as...
11
by: Girish Sahani | last post by:
I wrote the following code to concatenate every 2 keys of a dictionary and their corresponding values. e.g if i have tiDict1 = tiDict1 = {'a':,'b':} i should get tiDict2={'ab':} and similarly for...
11
by: Sheldon | last post by:
Hi, I have two arrays that are identical and contain 1s and zeros. Only the ones are valid and I need to know where both arrays have ones in the same position. I thought logical_and would work...
6
by: Tina I | last post by:
Hi everyone, I have a small, probably trivial even, problem. I have the following HTML: I need to make this into a dictionary like this: dictionary = {"METAR:" : "ENBR 270920Z 00000KT 9999...
6
by: saif.shakeel | last post by:
Hi, I have a dictionary which is something like this: id_lookup={ 16:'subfunction', 26:'dataId', 34:'parameterId', 39:'subfunction', 44:'dataPackageId', 45:'parameterId', 54:'subfunction',
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.