Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何在jinja中查找列表的值索引_Python_Jinja2_Ansible Template - Fatal编程技术网

Python 如何在jinja中查找列表的值索引

Python 如何在jinja中查找列表的值索引,python,jinja2,ansible-template,Python,Jinja2,Ansible Template,我正在使用ansible模板(Jinja2),如何获取/查找列表的值索引? 例如: listvar = ['abc', 'def', 'hij'] # i want get the index of value 'hij', it should get 2 我知道对和使用,还有其他简单的方法吗?您可以使用listvar.index('hij')。当元素不存在时要小心。谢谢,测试成功,我也会尝试这样做。{code>{{ansible\u play\u hosts.index('notexists

我正在使用ansible模板(Jinja2),如何获取/查找列表的值索引? 例如:

listvar = ['abc', 'def', 'hij']
# i want get the index of value 'hij', it should get 2

我知道对和使用
,还有其他简单的方法吗?

您可以使用listvar.index('hij')。当元素不存在时要小心。谢谢,测试成功,我也会尝试这样做。{code>{{ansible\u play\u hosts.index('notexists')如果在ansible\u play\u hosts else 999}中“notexists”}
您可以使用listvar.index('hij')。当元素不存在时请小心。谢谢,测试成功,我也会尝试这是正常的
{{ansible\u play\u hosts.index('notexists'),如果ansible\u play\u hosts else 999}中的'notexists'。