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


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.