In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.

When I was playing with Python in an interactive environment such as IPython, it was a generator type instead of a list type, so

In [2]: foo()
Out[2]: <generator object foo at 0x7f1f35a3dee8>

I think that there is an irritating experience. I think it became especially noticeable after Python3. In such a case, well, I should modify it to list (foo ()). Ctrl + A (or Home),'l','i','s','t','(', Ctrl + E (or End),')' And I have to press the 8 key. Tedious. I'm irritated.

I suddenly came up with it.

class Apply:
    def __init__(self, f):
        self.f = f
    def __lt__(self, x):
        return self.f(x)

L = Apply(list)

Once written,

In [2]: foo()
Out[2]: <generator object foo at 0x7f1f35a3dee8>

Even if it's irritating

In [8]: foo() >L
Out[8]: [0, 1, 4, 9, 16, 25, 36, 49, 64, 81]

You can easily make a list just by doing. If you create 50-apply.py in the $ HOME / .ipython / profile_default / startup directory, you can calm down and list it with > L after that.

Recommended Posts

In IPython, when I tried to see the value, it was a generator, so I came up with it when I was frustrated.
GCP's Cloud Shell Editor was clogged up with the Python development environment, so I managed to rebuild it in a vacant lot.
What I did when I was angry to put it in with the enable-shared option
I wanted to know the number of lines in multiple files, so I tried to get it with a command
When I tried to install PIL and matplotlib in a virtualenv environment, I was addicted to it.
When I tried the AtCoder Beginner Contest, it was a terrible result, so I look back
I also tried to imitate the function monad and State monad with a generator in Python
There was a doppelganger, so I tried to distinguish it with artificial intelligence (laughs) (Part 1)
A memorandum when I tried to get it automatically with selenium
When I tried to scrape using requests in python, I was addicted to SSLError, so a workaround memo
A story that didn't work when I tried to log in with the Python requests module
When I tried to run Python, it was skipped to the Microsoft Store
I tried to make a calculator with Tkinter so I will write it
I tried to display the altitude value of DTM in a graph
When I tried to change the root password with ansible, I couldn't access it.
When I tried to make a VPC with AWS CDK but couldn't make it
When I tried to create a virtual environment with Python, it didn't work
I set up TensowFlow and was addicted to it, so make a note
[Python & SQLite] I tried to analyze the expected value of a race with horses in the 1x win range ①
I tried to make the phone ring when it was posted at the IoT post
When I tried to do socket communication with Raspberry Pi, the protocol was different
A beginner tried coloring line art with chainer. I was able to do it.
It is troublesome to change the settings between the intranet and business trip / at home, so I was a little happy when I set up a forward proxy locally with Apache2.
I stumbled when I tried to install Basemap, so a memorandum
What I was addicted to when dealing with huge files in a Linux 32bit environment
Since there was a doppelganger, I tried to distinguish it with artificial intelligence (laugh) (Part 2)
I tried to create a Python script to get the value of a cell in Microsoft Excel
I wrote a doctest in "I tried to simulate the probability of a bingo game with Python"
The story I was addicted to when I specified nil as a function argument in Go
I don't like to be frustrated with the release of Pokemon Go, so I made a script to detect the release and tweet it
I tried to describe the traffic in real time with WebSocket
I tried to process the image in "sketch style" with OpenCV
A note I was addicted to when creating a table with SQLAlchemy
I tried to process the image in "pencil style" with OpenCV
I tried to make a site that makes it easy to see the update information of Azure
I tried to expand the database so that it can be used with PES analysis software
I was frustrated by Kaggle, so I tried to find a good rental property by scraping & machine learning
I tried to find out the difference between A + = B and A = A + B in Python, so make a note
Python: I tried to make a flat / flat_map just right with a generator
[Python] When I tried to make a decompression tool with a zip file I just knew, I was addicted to sys.exit ()
(Machine learning) I tried to understand the EM algorithm in a mixed Gaussian distribution carefully with implementation.
I was addicted to trying Cython with PyCharm, so make a note
[Words spelled to me when I was in the first grade ①] I'm not afraid to build a programming environment.
The tree.plot_tree of scikit-learn was very easy and convenient, so I tried to summarize how to use it easily.
When I made a treemap (area graph) with python, it was subtle, so when I used flourish, it felt pretty good.
Introduction to AI creation with Python! Part 2 I tried to predict the house price in Boston with a neural network
The file edited with vim was readonly but I want to save it
What I was addicted to when creating a web application in a windows environment
To output a value even in the middle of a cell with Jupyter Notebook
I tried to predict the horses that will be in the top 3 with LightGBM
I tried to use Resultoon on Mac + AVT-C875, but I was frustrated on the way.
I failed to install django with pip, so a reminder of the solution
When I tried to connect with SSH, I got a warning about free space.
I want to see a list of WebDAV files in the Requests module
I didn't understand the Resize of TensorFlow so I tried to summarize it visually.
A note I was addicted to when running Python with Visual Studio Code
A story that I was addicted to when I made SFTP communication with python
I referred to it when I got stuck in the django geodjango tutorial (editing)
I tried to create a model with the sample of Amazon SageMaker Autopilot
(Python: OpenCV) I tried to output a value indicating the distance between regions while binarizing the video in real time.
When I tried to create a project using Python on Docker with PyCharm, it didn't work, but it worked with Docker Compose.