I am getting the output from my previous executions something like this:

[{u'Value': '2018-06-21', u'Key': 'Deletion_Date'}]

I want to get only 2018-06-21 saved in a variable.

I tried this

deletion_date = response1['TagList'][0]['Value']

But I am getting error

deletion_date = response1['TagList'][0]['Value']
IndexError: list index out of range

Could someone help me with this or some alternative solution

closed as off-topic by Gaius, chicks, Pierre.Vriens, Tensibai Jul 2 '18 at 8:40

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about general programming problems are not on-topic unless they relate to DevOps in some way. You may be able to get help on Stack Overflow instead." – Gaius, chicks, Tensibai
If this question can be reworded to fit the rules in the help center, please edit the question.


You're not showing how the response example you shown relates to response1 (there is no 'TagList' in your example). It looks like response1['TagList'] is an empty list.

Otherwise you're on the right track (you can always check your exact case directly in the python shell):

$ python
Python 2.7.12 (default, Jul 01 2016, 15:36:53) [GCC] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> response = [{u'Value': '2018-06-21', u'Key': 'Deletion_Date'}]
>>> response[0]
{u'Key': 'Deletion_Date', u'Value': '2018-06-21'}
>>> response[0]['Value']

Not the answer you're looking for? Browse other questions tagged or ask your own question.