I just wrote the original material for the python sample code

background

The sample code written on the official website and books includes movies and comedy stories, so I summarized them. Most of the book scribbles say that "Python" is derived from "Flying Monty Python", but I feel that it is not the only one.

Since the sample code is written as an example, there is no intention of making variables, strings, or numbers, and the reader is only a guess. If it is a formal meeting, there are minutes, but there is no stupid person who uses resources until he leaves some comments in such a place.

Here are some of the codes I was interested in.

42

Python --Documentation --tutorial --if statement The sample code of is written like this.

if


>>> x = int(input("Please enter an integer: "))
Please enter an integer: 42
>>> if x < 0:
...     x = 0
...     print('Negative changed to zero')
... elif x == 0:
...     print('Zero')
... elif x == 1:
...     print('Single')
... else:
...     print('More')
...
More

Here, "42" is used as the input value. It's not always, but it's a little more frequent.

In other languages, there is a ruby on rails list method that returns the 42nd element. (1..50).to_a.forty_two It seems that you can write with.

first (items [0]) second (items [1]) third (items [2]) fifth (items [3]) forty_two(items[41]) You can get the 42nd element.

So, Mystery that forty_two is in Rails Array extension> [github](https://github.com/rails/rails/commit/e50530ca3ab5db53ebc74314c54b62b91b93 There was the following comment when I followed it with # commitcomment-8436).

tilsammans: 
http://en.wikipedia.org/wiki/Notable_phrases_from_The_Hitchhiker%27s_Guide_to_the_Galaxy#Answer_to_Life.2C_the_Universe_and_Everything_.2842.29

Looking at this Japanese version of wikipedia, ... With the phrase in the British science fiction novel "Galaxy Hitchhiking Guide" [The ultimate answer to your questions about life, space, and everything](https://ja.wikipedia.org/wiki/%E7%94%9F%E5%91%BD%E3%80%81%E5%AE % 87% E5% AE% 99% E3% 80% 81% E3% 81% 9D% E3% 81% 97% E3% 81% A6% E4% B8% 87% E7% 89% A9% E3% 81% AB % E3% 81% A4% E3% 81% 84% E3% 81% A6% E3% 81% AE% E7% A9% B6% E6% A5% B5% E3% 81% AE% E7% 96% 91% E5 % 95% 8F% E3% 81% AE% E7% AD% 94% E3% 81% 88), and there were 42 descriptions here.

The mouse in this series is "the part of a pan-dimensional creature with excellent intelligence protruding into our three dimensions."
The mice created Deep Sort, the second greatest computer of all ages and of all worlds, to find out "the ultimate answer to the question of life, the universe, and all things."
The answer that the computer gave over 7.5 million years was "42".

"Forty-two!」
Rune Qual shouted.
"It took 7.5 million years, that ’s it.?」
"I checked it thoroughly many times."
The computer responded.
"It's definitely the answer. Frankly, the problem is that you didn't know what the ultimate question was."

I don't know this novel, but it seems that 42 is recognized as the "ultimate answer" by overseas developers.

If you see "42" in the sample code, I think it's okay if you're alone ( ̄ ー  ̄).

Spam Eggs Sausage Bacon

Python --Documentation --Standard Library --Built-in--Dictionary View Objects

>>> dishes = {'eggs': 2, 'sausage': 1, 'bacon': 1, 'spam': 500}
>>> keys = dishes.keys()
>>> values = dishes.values()

>>> # iteration
>>> n = 0
>>> for val in values:
...     n += val
>>> print(n)
504

>>> # keys and values are iterated over in the same order (insertion order)
>>> list(keys)
['eggs', 'sausage', 'bacon', 'spam']
>>> list(values)
[2, 1, 1, 500]

['eggs','sausage','bacon','spam'] are variables and strings that you often see in sample code for sites and books.

This original story is Monty Python's control "spam", and as its name suggests, a large amount of spam appears. Occasionally'eggs',' sausage',' bacon' will appear. The etymology of spam emails also comes from here.

SPAM

Dead Parrot Python --Documentation --tutorial-Keyword Arguments

def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'):
    print("-- This parrot wouldn't", action, end=' ')
    print("if you put", voltage, "volts through it.")
    print("-- Lovely plumage, the", type)
    print("-- It's", state, "!")

#OK
parrot(1000)                                          # 1 positional argument
parrot(voltage=1000)                                  # 1 keyword argument
parrot(voltage=1000000, action='VOOOOOM')             # 2 keyword arguments
parrot(action='VOOOOOM', voltage=1000000)             # 2 keyword arguments
parrot('a million', 'bereft of life', 'jump')         # 3 positional arguments
parrot('a thousand', state='pushing up the daisies')  # 1 positional, 1 keyword

#NG
parrot()                     # required argument missing
parrot(voltage=5.0, 'dead')  # non-keyword argument after a keyword argument
parrot(110, voltage=220)     # duplicate value for the same argument
parrot(actor='John Cleese')  # unknown keyword argument

PARROT

Here are good and bad examples of function keyword arguments, but the function name is parrot.

There is also a scene in which Monty Python's Tale "Dead Parrot" claims that the pet shop clerk is alive even though the parrot is dead in the original story. Maybe it's like that. I don't understand the word, but I give a dead parrot an electric shock as an argument with voltage. It's black magic. : ghost:

marx brothers I don't see it in the official doc, but it appears in the sample code of Introduction Python3.

>>> marx_tuple = ("Groucho","Choico","Harpo")
>>> marx_tuple
('Groucho', 'Choico', 'Harpo')

The 'Groucho',' Choico', and'Harpo' that appear in the explanation of tuples are the member names of the Marx Brothers (normal people. I think they were in the maker of A ○ ...). He made his debut in the heyday of the talkie movie (1935-1960), a generation newer than Chaplin. In particular,'Groucho' had talk skills, so he appeared on TV programs in the 1950s when black-and-white television became popular in the United States and survived. 'Choico' was good at improvising piano playing, and'Harpo' was good at playing the harp of that name.

There is a movie "Duck Soup" in the movie, but the original English text is "duck so up". This is also expected, but I feel that the "soup" of beautiful soup seems to come from here.

Furthermore, the Drifters have the Marx Brothers as a motif, and it is said that the "Hige Dance" tale imitates the appearance of Groucho. (There is probably a document left about this story. It's 8 o'clock! How to make a group of all-TV art that creates laughter % E3% 81% A0% E3% 83% A7-% E5% 85% A8% E5% 93% A1% E9% 9B% 86% E5% 90% 88% E3% 81% AE% E4% BD% 9C% E3% 82% 8A% E6% 96% B9% E2% 80% 95% E7% AC% 91% E3% 81% 84% E3% 82% 92% E7% 94% 9F% E3% 81% BF% E5% 87% BA% E3% 81% 99% E3% 83% 86% E3% 83% AC% E3% 83% 93% E7% BE% 8E% E8% A1% 93-% E5% B1% B1% E7% 94 % B0-% E6% BA% 80% E9% 83% 8E / dp / 4575292044)). If you don't know, let's go to the Akasaka broadcasting station as a last resort!)

PostScript It seems that there is still a lot of source code contained in the original material, and I may have known only a few of them this time.

Well, even though there are quite a few comedy shows in Japan, they aren't often talked about in the IT industry.

Another factor may be that there are so many stories that make you laugh in the air that you can't put them into the code.

Well, the highest peak of comedy now seems to be Ega-chan. It seems that it recorded 1 million registrations in a week. ega-chan However, it seems that I haven't earned advertising revenue.

Since it is the same tension as when it caused a problem in Turkey around 2000, it seems that public opinion in a certain world region has become unbearable in terms of content, so even if you code the story of a Japanese comedian, it will spread to the world I thought about it.

Also, if there is a code that seems to have original material, I will introduce it somewhere again.

Recommended Posts

I just wrote the original material for the python sample code
I wrote the code for Gibbs sampling
[Python] Sample code for Python grammar
I just changed the sample source of Python a little.
I wrote the queue in Python
I wrote the stack in Python
I installed the retro game engine pyxel for Python on Mac and started the sample code
[Python beginner] I collected the articles I wrote
[Python] I tried substituting the function name for the function name
vprof --I tried using the profiler for Python
I tried python programming for the first time.
Code for checking the operation of Python Matplotlib
What I got into Python for the first time
I tried Python on Mac for the first time.
Specific sample code for working with SQLite3 in Python
I tried python on heroku for the first time
I felt that I ported the Python code to C ++ 98.
I tried running the sample code of the Ansible module
I just want to find the 95% confidence interval for the difference in population ratios in Python
I tried porting the code written for TensorFlow to Theano
I was hooked for 2 minutes with the Python debugger pdb
I wrote python in Japanese
Enable the virtualenv Python virtual environment for Visual Studio Code
I wrote the basic grammar of Python with Jupyter Lab
Python code memo for yourself
I didn't know how to use the [python] for statement
Miscellaneous notes that I tried using python for the matter
I downloaded the python source
I tried using the python module Kwant for quantum transport calculation
[Python] I wrote the route of the typhoon on the map using folium
Python> I made a test code for my own external file
I made a scaffolding tool for the Python web framework Bottle
AtCoder: Python: Daddy the sample test.
I wrote Fizz Buzz in Python
I liked the tweet with python. ..
Python parallel / parallel processing sample code summary
See python for the first time
What is the python underscore (_) for?
[Python] Read the Flask source code
Command for the current directory Python
[Fundamental Information Technology Engineer Examination] I wrote an algorithm for the maximum value of an array in Python.
I wrote a code to convert quaternions to z-y-x Euler angles in Python
I tried to refer to the fun rock-paper-scissors poi for beginners with Python
Python -I tried to restore the dictionary comprehensive notation to its original form-
[Python] I wrote a simple code that automatically generates AA (ASCII art)
AtCoder writer I wrote a script to aggregate the contests for each writer
I tried to get the authentication code of Qiita API with Python.
Sample code to get the Twitter API oauth_token and oauth_token_secret in Python 2.7
About Python code for simple moving average assuming the use of Numba
[Python] I examined the exe conversion method for distributing business efficiency tools.
I measured the speed of list comprehension, for and while with python2.7.
Tips for Python beginners to use the Scikit-image example for themselves 6 Improve Python code
Introducing the BOT framework Minette for Python
[Blender x Python] Let's master the material !!
Python Master RTA for the time being
[Python] Round up with just the operator
Launch the Discord Python bot for 24 hours.
I didn't know the basics of Python
I wrote the selection sort in C
I wrote unit tests for various languages
MongoDB for the first time in Python