我有一个简单的条件,需要检查字典中某个键的值是否包含特定的字符串[Completed]
。
示例:
'Events': [
{
'Code': 'instance-reboot'|'system-reboot'|'system-maintenance'|'instance-retirement'|'instance-stop',
'Description': 'string',
'NotBefore': datetime(2015, 1, 1),
'NotAfter': datetime(2015, 1, 1)
},
],
我需要检查Description
键是否以[Completed]
开头。即:
'Descripton': '[Completed] The instance is running on degraded hardware'
我该如何做?我正在寻找类似以下方式的解决方案:
if inst ['Events'][0]['Code'] == "instance-stop":
if inst ['Events'][0]['Description'] consists '[Completed]":
print "Nothing to do here"
'Code': 'instance-reboot'|'system-reboot'|'system-maintenance'|'instance-retirement'|'instance-stop'
- sidney