comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Nested data structures
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Nested data structures [message #89916] Wed, 24 December 2014 13:29 Go to next message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
I am trying to build a data structure that will allow me to specify a person by his State, city, street and street. (This is not my actual need, but it is analogous.) Thus I might specify (as metacode)

['Colorado']['Boulder']['Pearl'][9990] = 'John'

I assume this can be done with nested hashes or dictionaries, but I am having difficulty figuring out how to start. I started writing something like

person = [hash('colorado',['boulder','Denver'], hash('Arizona',[Tuscon','Phoenix'])

but I get lost in making the nesting clear. thanks for any help. --Wayne
Re: Nested data structures [message #89918 is a reply to message #89916] Wed, 24 December 2014 16:11 Go to previous messageGo to next message
Michael Galloy is currently offline  Michael Galloy
Messages: 1114
Registered: April 2006
Senior Member
On 12/24/14, 2:29 PM, wlandsman wrote:
> I am trying to build a data structure that will allow me to specify a person by his State, city, street and street. (This is not my actual need, but it is analogous.) Thus I might specify (as metacode)
>
> ['Colorado']['Boulder']['Pearl'][9990] = 'John'
>
> I assume this can be done with nested hashes or dictionaries, but I am having difficulty figuring out how to start. I started writing something like
>
> person = [hash('colorado',['boulder','Denver'], hash('Arizona',[Tuscon','Phoenix'])
>
> but I get lost in making the nesting clear. thanks for any help. --Wayne
>
>

Is something like this what you are trying to do?

IDL> person = hash('Colorado', hash('Boulder', 1, 'Denver', 2),
'Arizona', hash('Tucson', 3, 'Phoenix', 4))
IDL> (person['Colorado'])['Denver']
2

Mike
--
Michael Galloy
www.michaelgalloy.com
Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
Research Mathematician
Tech-X Corporation
Re: Nested data structures [message #89919 is a reply to message #89918] Wed, 24 December 2014 20:49 Go to previous messageGo to next message
chris_torrence@NOSPAM is currently offline  chris_torrence@NOSPAM
Messages: 528
Registered: March 2007
Senior Member
On Wednesday, December 24, 2014 5:11:54 PM UTC-7, Mike Galloy wrote:
> On 12/24/14, 2:29 PM, wlandsman wrote:
>> I am trying to build a data structure that will allow me to specify a person by his State, city, street and street. (This is not my actual need, but it is analogous.) Thus I might specify (as metacode)
>>
>> ['Colorado']['Boulder']['Pearl'][9990] = 'John'
>>
>> I assume this can be done with nested hashes or dictionaries, but I am having difficulty figuring out how to start. I started writing something like
>>
>> person = [hash('colorado',['boulder','Denver'], hash('Arizona',[Tuscon','Phoenix'])
>>
>> but I get lost in making the nesting clear. thanks for any help. --Wayne
>>
>>
>
> Is something like this what you are trying to do?
>
> IDL> person = hash('Colorado', hash('Boulder', 1, 'Denver', 2),
> 'Arizona', hash('Tucson', 3, 'Phoenix', 4))
> IDL> (person['Colorado'])['Denver']
> 2
>
> Mike
> --
> Michael Galloy
> www.michaelgalloy.com
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
> Research Mathematician
> Tech-X Corporation

And to make it even more convenient, you can simply append the subscripts inside the first set of brackets and it will automatically descend into the sub-hashes:

IDL> print,person['Colorado', 'Denver']
2

Happy Holidays,
Chris
Re: Nested data structures [message #89920 is a reply to message #89918] Fri, 26 December 2014 12:02 Go to previous message
wlandsman is currently offline  wlandsman
Messages: 743
Registered: June 2000
Senior Member
Thanks Mike and Chris for pointing me in the right direction.

I want to build the data structure one step at a time, and it took me a while to figure out how to add new cities, but concatenation works nicely. --Wayne

IDL> person['Colorado'] += hash('FtCollins',5)
IDL> person
{
"Colorado": {
"Boulder": 1,
"FtCollins": 5,
"Denver": 2
},
"Arizona": {
"Tucson": 3,
"Phoenix": 4
}
}


On Wednesday, December 24, 2014 7:11:54 PM UTC-5, Mike Galloy wrote:
> On 12/24/14, 2:29 PM, wlandsman wrote:
>> I am trying to build a data structure that will allow me to specify a person by his State, city, street and street. (This is not my actual need, but it is analogous.) Thus I might specify (as metacode)
>>
>> ['Colorado']['Boulder']['Pearl'][9990] = 'John'
>>
>> I assume this can be done with nested hashes or dictionaries, but I am having difficulty figuring out how to start. I started writing something like
>>
>> person = [hash('colorado',['boulder','Denver'], hash('Arizona',[Tuscon','Phoenix'])
>>
>> but I get lost in making the nesting clear. thanks for any help. --Wayne
>>
>>
>
> Is something like this what you are trying to do?
>
> IDL> person = hash('Colorado', hash('Boulder', 1, 'Denver', 2),
> 'Arizona', hash('Tucson', 3, 'Phoenix', 4))
> IDL> (person['Colorado'])['Denver']
> 2
>
> Mike
> --
> Michael Galloy
> www.michaelgalloy.com
> Modern IDL: A Guide to IDL Programming (http://modernidl.idldev.com)
> Research Mathematician
> Tech-X Corporation
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: IDLBridge problem with unknown ExecuteTimer method
Next Topic: ERROR: Attempt to subscript B with is out of range

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 15:10:00 PDT 2025

Total time taken to generate the page: 0.00969 seconds