Caculate age

Ben Patel benvpatel at yahoo.com
Sun Feb 2 20:38:48 EST 2003


Thanks Laura !
I was able to write up a little function that works. Here is what I have done so far - 
def mydict(b):
 if len(b) > 0:
            i=len(x)+1
            x[i] = i
            x[i] = b
            
        myvalues = x.values()
        myx = myvalues.pop(0)
        
        if myx == 'TEST':
            print 'Success - The 1st variable exist in the hash table >>>'
            return myx
        else:
            print 'Try again !' 
 
The only problem is that I have to initialize the dictionary x manually (x={}). 
 
-Thanks ! 

 Laura Creighton <lac at strakt.com> wrote:> --0-1253328135-1044223072=:10654
> Content-Type: text/plain; charset=us-ascii
> 
> 
> Thanks for your quick response. 
> I am trying to write a function which will take a String as an argument and a
> dd it to a hashtable. If the value entered is in the Hashtable then print it 
> or else error out. 

This will go better if you paste in what you get out of the
Python interpreter.

> Here is what I have written so far : 
> import sys 
> def mydict(y):

def makes a function. They are usually thought of like verbs.
So def make_a_dict(y): might be the sort of thing that you are looking
for. But I think that you simply want to in itialize your dictionary.

mydict={} will do this for you.
> #y = raw_input ("Please enter a String: ")
> if len(y) > 1:
> x={}

Now you have make an empty dictionary. I don't think you wanted to.

> #x={i:y}
> x[i] = i
> x[i] = y
> i = i+1

where did this i come from? remember that strings make great
keys for your dictionary. Numbers do not. 

> #return x.values()
> #print x.has_key(1)
> #y=x.keys()
> #z=x.values()
> #print y, z
> print x.keys()
> print x.values()

Now you would like to go back to raw_input, wouldn't you?
But you aren't in a loop, so python is going to keep wanting
the next statement. You need a way to tell it to go back to
the top.

> 
> Any advice ! 
> -Thanks

It is after midnight here in Sweden. I am going to bed. Good luck,
post your code with the results from the interpreter, and more
specific questions. If you can manage to not sent out messages
in HTML format, that would be great also.

Good luck,
Laura Creighton


---------------------------------
Do you Yahoo!?
Yahoo! Mail Plus - Powerful. Affordable. Sign up now
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20030202/6e4a7a9e/attachment.html>


More information about the Python-list mailing list