对 list 遍历

a_list = [1,2,3]
for index,iterm in enumerate(a_list):
print(index,iterm)

对 dict 遍历

dict = {"yellow":1, "red":2}
for k, v in dict.items():
print(k,v)

enumerate 和 dict.items()的更多相关文章

  1. dict.items vs six.iteritems

    python2里面,dict.items返回的是数组,six.iteritems(dict)则返回生成器. 意味着,dict很大的时候,后者不占用内存. >>> import six ...

  2. python 字典 dict items values keys

    dict.items() 1 >>> d = dict(one=1,two=2) 2 >>> it1 = d.items() 3 >>> it1 ...

  3. Python--字典的一些用法dict.items()

    1.dict.items() 例子1: 以列表返回可遍历的(键, 值) 元组数组. dict = {'Name': 'Runoob', 'Age': 7} print ("Value : % ...

  4. Python3基础 dict items 以元组的形式打印出字典的每一个项

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  5. python新手必躺的5大坑

    python新手必躺的5大坑 对于Python新手来说,写代码很少考虑代码的效率和简洁性,因此容易造成代码冗长.执行慢,这些都是需要改进的地方.本文是想通过几个案列给新手一点启发,怎样写python代 ...

  6. python学习之dict的items(),values(),keys()

    Python的字典的items(), keys(), values()都返回一个list >>> dict = { 1 : 2, 'a' : 'b', 'hello' : 'worl ...

  7. Python dict get items pop update

    一.get方法 dict = {'k1':1,'k2':2} dict.get('k1') 1 dict.get('k2') 2 dict.get('k3') None dict.get('k3',' ...

  8. 字典dict的深入学习(item() / items() 一致的)

    字典Dict的跟进学习: 一. items()方法的遍历:items()方法把字典中每对key和value组成一个元组,并把这些元组放在列表中返回. dict = {"name" ...

  9. python3基础: 元组tuple、 列表list、 字典dict、集合set。 迭代器、生成器

    一.元组: tuple Python 的元组与列表类似,不同之处在于元组的元素不能修改. 元组中的元素值是不允许删除的,但我们可以使用del语句来删除整个元组 tup2 = (111, 22, 33, ...

随机推荐

  1. 【转】关于BeanUtils.copyProperties的用法和优缺点

    一.简介:  BeanUtils提供对Java反射和自省API的包装.其主要目的是利用反射机制对JavaBean的属性进行处理.我们知道,一个JavaBean通常包含了大量的属性,很多情况下,对Jav ...

  2. 让 IE6支持max-height

    min-height min-height:100px; _height:100px max-height max-height:200px; overflow:auto;/*超出部分显示滚动条*/ ...

  3. python portia

    docker run -i -t --rm -v <PROJECTS_FOLDER>:/app/data/projects:rw -p 9001:9001 scrapinghub/port ...

  4. 输入输出参数 inout

    输入输出参数 inout 函数参数默认是常量.试图在函数体中更改参数值将会导致编译错误(compile-time error).这意味着你不能错误地更改参数值.如果你想要一个函数可以修改参数的值,并且 ...

  5. 一个合约访问另一个合约中的mapping

    参考链接:https://ethereum.stackexchange.com/questions/13616/accessing-a-public-mapping-within-a-contract ...

  6. Condition Variable使用及其Thread Cancellation线程取消

    条件变量Condition Variable的一般用法: 唤醒用法: struct { pthread_mutex_t mutex; pthread_cond_t cond; //whatever v ...

  7. c#解决Nullable类型的转换 (包含DataContract的序列化和反序列化以及 该例子应用在反射属性setvalue的时候有用)

    using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Reflect ...

  8. ACTIVITI 5.14事件监听器的BUG

    在ACTIVITI 5.14中,测试内部子流程时发现事件定义的事件监听器不能触发. <activiti:executionListener event="start" del ...

  9. PHP(六)PHP和HTML混合的一种形式

  10. 看图说说Sun HotSpot虚拟机对象