[PYTHON] I tried increasing or decreasing the number by programming

(Original story) I'd like to increase or decrease the number by programming http://blog.livedoor.jp/itsoku/archives/39361879.html

--

I tried it with Python

#Generator that increases or decreases the value by size
def repeat_range(range_size, offset = 0):

	def repeat_gen():
		signed = 1
		i = -1

		while True:
			i += signed
			if i == 0 :
				signed = 1
			if i == range_size -1:
				signed = -1
			yield i + offset

	return repeat_gen()


#Create iterations 1 to 4
repeat4  = repeat_range(4, 1)

for i in range(10):
	print repeat4.next(),

result


1 2 3 4 3 2 1 2 3 4

Recommended Posts

I tried increasing or decreasing the number by programming
I tried python programming for the first time.
I tried using the Datetime module by Python
I tried using the functional programming library toolz
I tried competitive programming
I tried shell programming
I tried to predict the presence or absence of snow by machine learning.
I tried the changefinder library!
I tried programming the chi-square test in Python and Java.
I tried to tabulate the number of deaths per capita of COVID-19 (new coronavirus) by country
I tried the TensorFlow tutorial 1st
I tried the Naro novel API 2
I tried to visualize the Beverage Preference Dataset by tensor decomposition.
I tried the TensorFlow tutorial 2nd
Can I pass the first grade of math test by programming?
I tried to summarize the commands used by beginner engineers today
I tried to predict by letting RNN learn the sine wave
I tried the Naruro novel API
I tried to solve the shift scheduling problem by various methods
I tried to move the ball
I tried using the checkio API
I tried to estimate the interval.
I tried SIGNATE "[Practice question] Predicting the number of rental bicycle users"
I tried moving the image to the specified folder by right-clicking and left-clicking
I tried to summarize the general flow up to service creation by self-education.
765 I tried to identify the three professional families by CNN (with Chainer 2.0.0)
(Python) I tried to analyze 1 million hands ~ I tried to estimate the number of AA ~
I tried to find the optimal path of the dreamland by (quantum) annealing
I tried to verify and analyze the acceleration of Python by Cython
I checked the number of closed and opened stores nationwide by Corona
I tried fractal dimension analysis by the box count method in 3D
I tried to summarize the Linux commands used by beginner engineers today-Part 1-
I tried to solve the inverted pendulum problem (Cart Pole) by Q-learning.
I tried to verify the result of A / B test by chi-square test
I tried to analyze the New Year's card by myself using python
I tried the TensorFlow tutorial MNIST 3rd
I tried the asynchronous server of Django 3.0
I tried to summarize the umask command
I tried to recognize the wake word
I tried the OSS visualization tool, superset
I tried to summarize the graphical modeling.
I tried to touch the COTOHA API
Quadratic programming by the interior point method
Python: I tried the traveling salesman problem
I tried playing with the image with Pillow
I tried shortening Python's FizzBuzz little by little
I tried the Python Tornado Testing Framework
I tried using the BigQuery Storage API
I tried to predict the number of people infected with coronavirus in Japan by the method of the latest paper in China
I tried to predict the change in snowfall for 2 years by machine learning
I tried to rescue the data of the laptop by booting it on Ubuntu
I tried to pass the G test and E qualification by training from 50
I tried searching for files under the folder with Python by file name
I tried "smoothing" the image with Python + OpenCV
I tried to program bubble sort by language
I tried web scraping to analyze the lyrics.
I tried using scrapy for the first time
I tried the pivot table function of pandas
[Python] I tried substituting the function name for the function name
I tried cluster analysis of the weather map
I tried hitting the Qiita API from go