python自定义迭代器对象以及可迭代对象
2024-09-05 23:51:54
# coding=utf8
from collections import Iterator
from collections import Iterable #迭代器对象
class OwnIteror( Iterator ):
def __init__(self , arrs ):
self.index = 0
self.arrs = arrs
def next(self):
if self.index > len( self.arrs ) - 1:
raise StopIteration
else:
self.index +=1
return self.arrs[ self.index - 1 ] #可迭代对象
class OwnIterable( Iterable ):
def __init__(self , arrs ):
self.arrs = arrs
def __iter__(self):
return OwnIteror( self.arrs ) for item in OwnIterable( [ 1,2,3,4,4,6 ] ):
print item
最新文章
- java关键字之final
- 岁末年初3Q大战惊现高潮,360震撼推出Android ";3Q"; IM即时通讯
- as3 同屏1000+动画,不掉帧。解决方案。
- (*p)++和*(p++)和*p++的区别
- 获取真实ip的报告
- UserDefault 用户首选项读写 swift
- 【Search a 2D Matrix】cpp
- SQL Server 127个SQL server热门资料汇总
- 什么是马甲APP?怎么用马甲APP导流
- python运维开发之第十一天(RabbitMQ,redis)
- Push Notification总结系列(一)
- iReport使用教程
- 将Asp.Net Core和corefx移植到.Net 4.0
- php session序列化攻击面浅析
- JDK8到JDK12各个版本的重要特性整理
- You have new mail in /var/spool/mail/root消除提示的方法
- const引用和函数占位参数遇上默认参数以及内联函数
- Method not found: 'System.Data.Entity.ModelConfiguration.Configuration.XXX
- Spark SQL初始化和创建DataFrame的几种方式
- HDU 2106 母猪的故事
热门文章
- git@github.com出现Permission denied (publickey)
- Reference与ReferenceQueue
- Python---基础---dict和set
- django 多条数据显示的坑(怪自己)
- RMQ Fanout
- Fckeditor实现WORD粘贴图片自动上传
- luogu P1020 导弹拦截 x
- 【HDOJ6628】permutation 1(dfs)
- 李满春与WebGIS
- SLF4J: The requested version 1.6 by your slf4j binding is not compatible with [1.5.5, 1.5.6]