How to transform user input string into correct object type
Question: I am using Python (2.7) along with Natural Language Toolkit (3.2.1) and
WordNet. I am _very_ new to programming.

I am trying to write a program which asks the user for a word, then prints
synonym sets for that word, then asks the user which synonym set it wants to
see the lemmas for.

The problem is that `raw_input` only accepts strings, so when I try to use the
method `.lemma_names()` on the user input, I get the error `AttributeError:
'str' object has no attribute 'lemma_names'`.

Here is the code:

    
    
    from nltk.corpus import wordnet as wn
    
    w1 = raw_input ("What is the word? ")
    
    #This prints the synsets for w1, thus showing them what format to use in the next question.
    
    for synset in wn.synsets(w1):
        print synset
    
    #This asks the user to choose the synset of w1 that interests them.
    
    synset1 = raw_input ("Which sense are you looking for? [Use same format as above]")
    
    #This prints the lemmas from the synset of interest.
    
    for x in synset1.lemma_names():
        print x
    

My question is, how do I transform the user's input from a string to a synset
type which I can use the `.lemma_names()` method on?

I apologize if this question is so basic as to be off-topic. If so, let me
know.


Answer: Try this:

    
    
    from nltk.corpus import wordnet as wn
    
    w1 = raw_input ("What is the word? ")
    
    synset_dict = dict()
    for synset in wn.synsets(w1):
        name = synset.name()
        synset_dict[name] = synset
        print name
    
    synset1 = raw_input ("Which sense are you looking for? [Use same format as above] ")
    
    if synset1 in synset_dict:
        synset = synset_dict[synset1]
        for lemma in synset.lemma_names():
            print lemma
    

