AllenOR灵感

# 概述

for  v   in d.values():

for k,v  in d.items():

#判断对象是否可迭代

from collections import Iterable

isinstance('abc',Iterable)

#添加下标

for x,y in enumerate([(1,1),(2,3),(4,5)]):

# 详解

## 1.迭代list

``>>> d={'a':1,'b':2,'c':3}``
``#输出values``

>>> for v in d.values():
... print v
...
1
3
2

#同时输出key，value

``````>>> for k, v in d.items():
...      print k,v
...
#输出
a 1
c 3
b 2``````

## 2.字符串迭代

``````>>> for a in 'adfa':
...      print a
...
a
d
f
a``````

## 3.判断一个对象是否可迭代

``````>>>from collections import Iterable
#判断字符串是否可迭代
>>>isinstance('abc',Iterable)
#输出
True#判断list是否可迭代``````
``````>>>isinstance([1,2,3],Iterable)
#输出
True#判断整数是否可迭代``````

>>> isinstance(12345,Iterable)
False

4.对list实现下标循环

``````>>> for i,value in enumerate(['a','b','c']):
...      print(i,value)
...
(0, 'a')
(1, 'b')
(2, 'c')
>>> for i,value in enumerate(['a','b','c']):
...      print  i,value
...
0 a
1 b
2 c``````

``````>>> for x,y in [(1,1),(2,3),(4,5)]:
...      print x,y
...
1 1
2 3
4 5``````

>>> for x,y in enumerate([(1,1),(2,3),(4,5)]):
... print x,y
...
0 (1, 1)
1 (2, 3)
2 (4, 5)

### AllenOR灵感

2018/05/10
0
0

2018/05/10
0
0

Aikenwu
2018/08/13
0
0

2018/05/10
0
0
python——高级特性（2）

2018/05/04
0
0

Giraph源码分析（八）—— 统计每个SuperStep中参与计算的顶点数目

4
0
Xss过滤器（Java）

10
0
Navicat 快捷键

9
0
Set 和 Map

Set 1：基本概念 类数组对象, 内部元素唯一 let set = new Set([1, 2, 3, 2, 1]); console.log(set); // Set(3){ 1, 2, 3 } [...set]; // [1, 2, 3] 接收数组或迭代器对象 ...

4
0
PyTorch入门笔记一

6
0