2017-04-11 Python> I tried generator> I was taught generator expression / generator function / next ()

@ Introducing Python: Modern Computing in Simple Packages by Bill Lubanovic (No. 2749 / 12833)

I tried the generator. It seems to use yield that I saw for the first time in Unity.

Reference: 9.9. Generators

I've tried.

http://ideone.com/byVYbr

def my_odds(last=10, step=1):
	number = 0
	while number < last:
		if number % 2 == 1:
		  yield number
		number += step

alist = my_odds(10, 1)
for elem in alist:
	print(elem)

result


Success	time: 0.02 memory: 28384 signal:0
1
3
5
7
9

~~ 6.2.8 Generator expression ~~

@ shiracamus's Comment pointed out the difference between "generator expression" and "generator function". He also taught me about next ().

Thank you for the information.

Recommended Posts

2017-04-11 Python> I tried generator> I was taught generator expression / generator function / next ()
[Python] Generator function
[Python] I tried substituting the function name for the function name
I tried function synthesis and curry with python
I tried Python> autopep8
I tried Python> decorator
I tried fp-growth with python
I tried scraping with Python
I tried Python C extension
[Python] I tried using OpenPose
I tried gRPC with Python
I tried scraping with python
I tried to implement the mail sending function in Python
I also tried to imitate the function monad and State monad with a generator in Python
I tried to touch Python (installation)
I tried to make a regular expression of "amount" using Python
I tried web scraping with python.
I tried to make a regular expression of "time" using Python
I tried to make a regular expression of "date" using Python
I tried using Thonny (Python / IDE)
I tried Grumpy (Go running Python).
Python> Comprehension> cells> I was taught how to use double comprehension / itertools
I tried running prolog with python 3.8.2.
I tried Line notification in Python
I tried SMTP communication with Python
[Python] I tried using YOLO v3
I tried to make an image similarity function with Python + OpenCV
Python: I tried to make a flat / flat_map just right with a generator
When I tried to run Python, it was skipped to the Microsoft Store
I tried to summarize Python exception handling
I tried to implement PLSA in Python
I tried to implement permutation in Python
Wrangle x Python book I tried it [2]
I tried scraping Yahoo News with Python
I tried to implement PLSA in Python 2
Python3 standard input I tried to summarize
I tried sending an email with python.
I tried using Bayesian Optimization in Python
I tried non-photorealistic rendering with Python + opencv
I tried using UnityCloudBuild API from Python
I tried to implement ADALINE in Python
I tried a functional language with Python
I tried recursion with Python ② (Fibonacci sequence)
I tried to implement PPO in Python
Python: I tried the traveling salesman problem
Wrangle x Python book I tried it [1]
Mayungo's Python Learning Episode 8: I tried input
[Python] I tried to calculate TF-IDF steadily
I tried scraping Yahoo weather (Python edition)
I tried to touch Python (basic syntax)
What I was addicted to Python autorun
I tried the Python Tornado Testing Framework
#I tried something like Vlookup with Python # 2
[Python] function
I tried to explain what a Python generator is for as easily as possible.
I tried using Google Translate from Python and it was just too easy
[Python] Smasher tried to make the video loading process a function using a generator
[Python] I tried to get the type name as a string from the type function
python function ②
I tried to predict next year with AI
[Python / DynamoDB / boto3] List of operations I tried