【问题标题】:How to get value from list using index?如何使用索引从列表中获取价值?
【发布时间】:2018-01-15 16:14:29
【问题描述】:

我必须尝试使用​​索引从列表中逐一获取值,并且我已尝试获取索引值并分别一一更新我的阶段。

我的python代码如下:

for ress in status_list:
    print"res", ress
    #self.workflow_stages = ress
    if ress:
        self.workflow_stages = ress
        for index, item in enumerate(status_list):
            print "test::", index
            index_init = index
            print"index_init:::", index_init
            next = index_init + 1
            print "next", next
            lent = len(status_list)
            print"lent", lent
        return True

谢谢。

【问题讨论】:

    标签: python-2.7 function loops odoo-10 enumerate


    【解决方案1】:

    这个for index, item in enumerate(status_list): 意味着index 变量保存了您各自的status_list 索引,而item 变量保存了您的值。所以在给定的for 循环中,item 将保存对应的index. 的值

    通常,如果您不使用enumerate 功能来迭代列表,您可以像status_list[index] 那样访问列表的值

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-01-29
      • 1970-01-01
      • 2021-10-06
      • 1970-01-01
      • 2020-08-11
      • 2016-03-11
      • 1970-01-01
      相关资源
      最近更新 更多