Python enumerate用法

来源:互联网 发布:怎么养才能加入淘宝网 编辑:程序博客网 时间:2024/05/17 02:59
    在同时需要用到index和value值的时候可以用到enumerate,参数为可遍历的变量,如字符串,列表等,返回enumerate类。
例:
import strings = string.ascii_lowercasee = enumerate(s)print sprint list(e)
输出结果为: 
[(0, 'a'), (1, 'b'), (2, 'c'), (3, 'd'), (4, 'e'), (5, 'f'), (6, 'g'), (7, 'h'),
 (8, 'i'), (9, 'j'), (10, 'k'), (11, 'l'), (12, 'm'), (13, 'n'), (14, 'o'), (15,
 'p'), (16, 'q'), (17, 'r'), (18, 's'), (19, 't'), (20, 'u'), (21, 'v'), (22, 'w
'), (23, 'x'), (24, 'y'), (25, 'z')]




转自:http://www.2cto.com/kf/201212/179579.html