I wrote python in Japanese

I noticed that Japanese variable names can be used now, so I tried to see how much I could write in Japanese.

# -*- coding: utf-8 -*-
from magic import*


#Make products for sale
price list=dictionary()
price list["Apple"] = 100
price list["Mandarin orange"] = 50
price list["melon"] = 200

Purchase history=list()

#Make a purchase history appropriately
for number of times in serial number list(10):
Product name list=price list.Get all the names()
Product name number=Get a random number(0,length(Product name list) - 1)
Purchase history.Stick(list(商品名list)[Product name number])

display("=====Purchase history=====")
for number of times,Purchased items in count(Purchase history):
display("%dth time:%s" % (Number of times+ 1,Purchased item))

#Calculate total payment
Total payment= 0
for Purchased Items in Purchase History:
Total payment+=price list[Purchased item]
display("=====Total payment=====")
display(Total payment)

output

=====Purchase history=====
First time:Mandarin orange
Second time:melon
Third time:Apple
4th:melon
5th time:melon
6th time:Mandarin orange
7th time:Mandarin orange
8th time:Mandarin orange
9th time:Mandarin orange
10th time:melon
=====Total payment=====
1150

おまじない.py

Magic for writing programs in Japanese

Magic.py


# -*- coding: utf-8 -*-
import builtins
import random

_builtin_list = builtins.list
_builtin_dict = builtins.dict


#List replacement class definition
class list(_builtin_list):
Stick= _builtin_list.append
Stick the list together= _builtin_list.extend
Put in= _builtin_list.insert
Erase=Kesu= _builtin_list.remove
Take out=Take out= _builtin_list.pop
Erase everything=Erase everything= _builtin_list.clear
look for=Search= _builtin_list.index
count=Count= _builtin_list.count
Line up=Line up= _builtin_list.sort
Arrange upside down=Arrange upside down= _builtin_list.reverse
copy= _builtin_list.copy


#Dictionary replacement class definition
class dictionary(_builtin_dict):
Get all names and content=Get all the names= _builtin_dict.items
Get all the names=Get all the names= _builtin_dict.keys
Get all the contents=Get it all= _builtin_dict.values

Erase everything=Erase everything= _builtin_dict.clear
copy= _builtin_dict.copy
get= _builtin_dict.get
Take out=Take out= _builtin_dict.pop
Pop out name and content=Extract name and content= _builtin_dict.popitem
Incorporate=Incorporate= _builtin_dict.setdefault
Combine=To be sick= _builtin_dict.update


#Built-in function alias definition
display=Hyouji= print
length=Length= len
Get a random number=Get a random kazu= random.randint
Get a random decimal=Get a random shosou= random.random
Serial number list=Goodwill list= range
Count=I'll give you= enumerate

dictionary=Jisho

#Built-in object replacement
builtins.list =list
builtins.dict =Jisho


def __test():
    #Problem verification code
    data_list = list()
    data_list=list()
    data_Comprehension list= []

    print(["data_list", type(data_list)])
    print(["data_list", type(data_list)])
    print(["data_Comprehension list", type(data_Comprehension list)])
    """
output
    ['data_list', <class '__main__.list'>]
    ['data_list', <class '__main__.list'>]
    ['data_Comprehension list', <class 'list'>]

Unfortunately there is a problem that the list of comprehensions cannot be replaced
    """


if __name__ == "__main__":
    __test()

It's a pity that the included List and Dict classes can't be replaced as I'm trying with __test ().

Recommended Posts

I wrote python in Japanese
I understand Python in Japanese!
I wrote Fizz Buzz in Python
I wrote the queue in Python
I wrote the stack in Python
Japanese output in Python
A memo that I wrote a quicksort in Python
I wrote a class in Python3 and Java
I wrote "Introduction to Effect Verification" in Python
I wrote a Japanese parser in Japanese using pyparsing.
What I learned in Python
Get Japanese synonyms in Python
I wrote Gray Scale in Pytorch
I learned about processes in Python
I can't install scikit-learn in Python
I tried Line notification in Python
How to handle Japanese in Python
I wrote an empty directory automatic creation script in Python
I put Python 2.7 in Sakura VPS 1GB.
Quadtree in Python --2
Python in optimization
CURL in python
I tried to implement PLSA in Python
Metaprogramming in Python
Python 3.3 in Anaconda
Geocoding in python
SendKeys in Python
I tried to implement permutation in Python
Meta-analysis in Python
I made a payroll program in Python!
Unittest in python
Comparison of Japanese conversion module in Python3
I started python
I tried to implement PLSA in Python 2
Epoch in Python
Discord in Python
I wrote matplotlib
Sudoku in Python
I tried using Bayesian Optimization in Python
DCI in Python
quicksort in python
nCr in python
I wrote the code to write the code of Brainf * ck in python
I can't debug python scripts in Eclipse
N-Gram in Python
Programming in python
I wrote a function to load a Git extension script in Python
I implemented Cousera's logistic regression in Python
Plink in Python
I tried to implement ADALINE in Python
I wrote the selection sort in C
Constant in python
I wanted to solve ABC159 in Python
I tried to implement PPO in Python
Lifegame in Python.
FizzBuzz in Python
I wrote a script to extract a web page link in Python
Sqlite in python
StepAIC in Python
N-gram in python
I searched for prime numbers in python