[Tutor] dictionary values in strings
William O'Higgins
william.ohiggins at utoronto.ca
Fri May 20 20:38:47 CEST 2005
On Thu, May 19, 2005 at 09:47:50PM +0100, Max Noel wrote:
>
>On May 19, 2005, at 20:49, William O'Higgins wrote:
>
>>I am trying to discover the syntax for call on a dictionary of
>>lists by
>>key and index.
>>
>>The data structure looks like this:
>>
>>dol = {'key1':['li1','li2','li3'],'key2':['li1','li2','li3'],\
>>'key3':['li1'li2,'li3','']}
>>
>>The keys are passed to a function as arguments, and I want the
>>value of
>>the specified list index. This is what I *thought* it would look
>>like:
>>
>>dol.key(argument)[0] # would return li1 when argument equals key1
> What you are looking for can be achieved like this:
>
>>>> dol = {'key1':['li1','li2','li3'],'key2':['li1','li2','li3'],\
>... 'key3':['li1', 'li2','li3','']}
>>>> dol['key1'][0]
>'li1'
Ah, of course, it makes sense that an associative array, referenced one
array at a time, would use array notation. Ah, crap, I'm speaking Perl
again. Make that "it makes sense that a linked list, referenced one
list at a time, would use list notation". Thanks.
--
yours,
William
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://mail.python.org/pipermail/tutor/attachments/20050520/193a6910/attachment.pgp
More information about the Tutor
mailing list