Post Reply 
Seeking advice from seasoned Python programmer
10-20-2017, 10:35 AM
Post: #6
RE: Seeking advice from seasoned Python programmer
(10-20-2017 07:56 AM)emece67 Wrote:  Happy to know it was helping.

You can also use a dictionary to store your structure, as:

a = {'array':[1, 2, 3], 'scalar1':4, 'scalar2':5} # your structure
b = {'scalar2':10, 'scalar1':9, 'array':[6, 7, 8]} # another one, just to remark that order is unimportant now
c = [a, b] # an array containing two of them

then c[1] returns {'array': [6, 7, 8], 'scalar1': 9, 'scalar2': 10}, which is b
c[1]['array'] returns [6, 7, 8] which is the array in b
c[1]['array'][2] returns 8, which is the last member of the array inside b.
c[1]['scalar1'] returns 9, which is the 1st scalar in b.

Perhaps more legible. Regards.

Thanks! Your solution ALSO WORKED. It was easy to go from the first solution to this one since I was using variables to select the proper indices for the swarm array of structures. All I had to do is search and replace these variable names and enclose them in single quote. Program works like a charm!

Thanks!!!
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: Seeking advice from seasoned Python programmer - Namir - 10-20-2017 10:35 AM



User(s) browsing this thread: 1 Guest(s)