[Tutor] what do I use for this?

Don Arnold darnold02 at sprynet.com
Sun Mar 14 14:29:33 EST 2004


On Mar 14, 2004, at 1:00 PM, GREENDAY31087 at aol.com wrote:

> I want to make a script that asks for a port number and returns its 
> meaning. Since there are a few thousand ports, I just want to start 
> with common ones. What would I use in this program? An array(s)?<Jimmy 
> Page .jpg>_______________________________________________
>

Although you could use a list (Python's version of an array), you're 
better off using a dictionary here:

 >>> ports = {80:'HTTP', 70: 'Gopher', 79: 'finger'}
 >>> print ports[80]
HTTP

That way, you won't be wasting memory with a list thousands of items 
long were only a relative few are actually populated.

HTH,
Don
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 728 bytes
Desc: not available
Url : http://mail.python.org/pipermail/tutor/attachments/20040314/bd7569e9/attachment.bin


More information about the Tutor mailing list