python 发电机的实践问题

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python 发电机的实践问题相关的知识,希望对你有一定的参考价值。

#Generator practice with classes

class Link:
	
	def __init__(self, first, next=None):
		self.first = first
		self.next = next
		
	def __repr__(self):
		return "({0}, {1})".format(self.first, self.next)
		
		
#Question 1
#Define a generator that on each next() call, returns a linked list of 
#numbers from 0 to infinity, making the chain one link longer each time
"""
   f = lazy_numbers()
=> None
   next(f)
=> (0, None)
   next(f)
=> (0, (1, None))
   next(f)
=> (0, (1, (2, None)))
   next(f)
=> (0, (1, (2, (3, None))))
   next(f)
=> (0, (1, (2, (3, (4, None)))))
   next(f)
=> (0, (1, (2, (3, (4, (5, None))))))
   next(f)
=> (0, (1, (2, (3, (4, (5, (6, None)))))))
"""
def lazy_numbers():
	pass
		
		
#Question 2
#define a generator that yields the sequence of strings of integers from 1 to infinity, with each next() call returning the next string.
#You cannot use integers for this problem. You must construct integers with strings
#Hint the .join method of an empty string joins an array of strings together
# "".join(["a", "b"]) => "ab"
"""
   f = intseq()
=> None
   next(f)
=> '1'
   next(f)
=> '2'
   next(f)
=> '3'
   next(f)
=> '4'
   next(f)
=> '5'
   next(f)
=> '6'
   next(f)
=> '7'
   next(f)
=> '8'
   next(f)
=> '9'
   next(f)
=> '10'
"""
def intseq():
	pass
						

"""String Drawing Practice"""

#Question 3
#Define a generator that draws a zigzag line, of some width w. it will generate an infinite number of moving lines
#to mark the line use a star *
#HINT:use the join method here 
def zigzag(w):
	pass

以上是关于python 发电机的实践问题的主要内容,如果未能解决你的问题,请参考以下文章

机器人控制器编程实践指导书旧版-实践四 步进电机(执行器)

真正源于产业实践的深度学习框架丨PaddlePaddle年终回顾

python 发电机

python 来源列出csv发电机

python 发电机!!!

python 发电机