Python Intro - zip object
来源:互联网 发布:mac 抹掉磁盘名称 编辑:程序博客网 时间:2024/06/04 18:05
#!/usr/local/bin/python3
try:
import numpy as np
except ImportError:
print("numpy is not installed")
sizes = [37, 5, 6];
print(sizes[-1]);
result = zip(sizes[:-1], sizes[1:]);
ll = len(result); #cause error: ll = len(result); TypeError: object of type 'zip' has no len()
print(*result); # correct deference, output (37, 5) (5, 6)
print("len of result = ", ll);
正确的代码如下:
#!/usr/local/bin/python3
import copy;
try:
import numpy as np
except ImportError:
print("numpy is not installed")
sizes = [37, 5, 6];
print(sizes[-1]);
result = zip(sizes[:-1], sizes[1:]);
tt = copy.deepcopy(result);
tt = tuple(tt);
ll = len(tt);
print("result = ", *result);
print("tuple = ", tt);
print("len of result = ", ll);
运行结果如下:
6
result = (37, 5) (5, 6)
tuple = ((37, 5), (5, 6))
len of result = 2
=============================================
try:
import numpy as np
except ImportError:
print("numpy is not installed")
tt = list(tt);
ll = len(tt);
print("list = ", tt);
print("len of result = ", ll);
result = (37, 5) (5, 6)
list = [(37, 5), (5, 6)]
len of result = 2
- Python Intro - zip object
- Python intro
- Python Intro
- Python Intro
- Python Intro
- Python Intro
- Python Intro
- Python Intro
- 1.8 - [intro.object] - 【总则.对象】
- Python Effective Programming - Intro
- Python-0(Intro)
- Python DM Learning Intro
- python中使用zip函数出现<zip object at 0x02A9E418>
- python中使用zip函数出现<zip object at 0x02A9E418>
- python zip() zip(*arg)
- IOS Dev Intro - Object C Forward Declaration
- IOS Dev Intro - Object Instance Type
- IOS Dev Intro - Object-C Class
- UVA - 12545 Bits Equalizer 贪心
- IOS的AppDelegate方法中的事件触发调用
- 摄影师培训学校哪里好?
- 黑马程序员——OC语言基础篇---核心语法
- html5 地理定位
- Python Intro - zip object
- 详解Android动画之Tween Animation
- Spark-1.3.1部署在hadoop-2.6.0
- Android 4.4 meminfo 实现分析
- 设置Activity为全屏显示的两种方法
- 泛型&集合
- mysql在sql语句中将时间戳格式化
- Git简介
- LRUCache