-1

I want to get the first value from a sequence for a key within a dictionary object.

This is the dictionary object:

{0: (mdb.models['EXP-100'].parts['hatpart-100'].vertices[1],
    (62.5242172081597, 101.192447407436, 325.0))}

The Key is 0, and I'd like to get the first value in the sequence of values (vertex object and coordinates), specifically the vertex object.

isok89
  • 41
  • 1
  • 5

1 Answers1

0

When you're trying to get a specific item from a dictionary containing a list you can do it by indicating the key and then index that you're looking for. So:

your dictionary ={'key':[1,2,3]}

result = your_dictionary['key'][0]

where key is the first item you want and if it contains a list, then the "0" is asking for the first item of the list.

The above will return the value "1".

You can iterate over this to get all values and you can add as many [] as you need to get to the specific value you need.

That being said, your data doesn't look quite right. The dictionary should contain "key":"object" sets. Those objects can be further dictionaries themselves or lists, but what you've provided seems to be off. You may have to manipulate the data to fit what you need it to do before your can perform any operations on it. This could help with that first: "Deparsing" a list using pyparsing

Community
  • 1
  • 1
beerandsmiles
  • 134
  • 3
  • 12
  • I asked the same question here but more detailed http://stackoverflow.com/questions/39030382/abaqus-python-getclosest-command Problem I have is that the object I get isn't a standalone object but again a dictionary, so this is more of a abaqus problem – isok89 Aug 19 '16 at 13:01