[PYTHON] How to quickly create array sample data during coding

I'm currently studying python to learn one scripting language. Sample data is often needed when learning a programming language.

This time, how to quickly create array data (strictly, list in python) with vim + bash.

environment

I wrote it properly, but I don't think the environment will be a problem.

Data creation

Open the source file with vim.

$ vim sample.py

I want to assign the data of the numerical string in ascending order to the list array in the following state.

#!/usr/bin/python

array = [
]

for i in array:
    print i

At that time, vim's command line mode bursts. Bring the cursor to ```array = [`` `on the 3rd line and execute the following in normal mode.

:r! echo {1..100}, | xargs -n 10

As a result, a string of numbers is inserted as shown below.

array = [
1, 2, 3, 4, 5, 6, 7, 8, 9, 10,
11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30,
31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50,
51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70,
71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90,
91, 92, 93, 94, 95, 96, 97, 98, 99, 100,
]

Since',' is added to the last element, it may be necessary to delete it depending on the language used. There is no grammatical problem with python. After that, please shape it appropriately such as indentation. (Select a range in normal mode of vim and'>' is easy)

In command line mode, if you do your best with seq instead of echo, you can process it a little more.

Postscript

For example, in python, the above data can be created easily and concisely by using a built-in function such as range, but this time I wanted to show that "vim + bash can be used for general purposes and easily shorten the time". So please understand that point.

Recommended Posts

How to quickly create array sample data during coding
How to create sample CSV data with hypothesis
Randomly sample MNIST data to create a dataset
How to create data to put in CNN (Chainer)
How to handle data frames
[Python] How to FFT mp3 data
How to read e-Stat subregion data
How to deal with imbalanced data
How to create a Conda package
How to create your own Transform
How to deal with imbalanced data
How to create an email user
How to create a virtual bridge
How to create / delete symbolic links
How to Data Augmentation with PyTorch
[Python] How to swap array values
[Python] How to store a csv file as one-dimensional array data
How to create a Dockerfile (basic)
How to create a large amount of test data in MySQL? ??
How to create a config file
How to collect machine learning data
[Development environment] How to create a data set close to the production DB
How to collect Twitter data without programming
How to create a git clone folder
How to create an NVIDIA Docker environment
Create document classification data quickly using NLTK
How to use CUT command (with sample)
How to create a repository from media
How to use "deque" for Python data
How to handle time series data (implementation)
How to read problem data with paiza
How to quickly create a morphological analysis environment using Elasticsearch on macOS Sierra
[For recording] Keras image system Part 1: How to create your own data set?
How to create large files at high speed
How to create a Python virtual environment (venv)
How to create a function object from a string
How to create explanatory variables and objective functions
How to create a JSON file in Python
[Django] How to get data by specifying SQL.
[Python] How to read data from CIFAR-10 and CIFAR-100
How to create an OCF compliant resource agent
How to scrape horse racing data with BeautifulSoup
How to use data analysis tools for beginners
How to quickly install h5py on Windows 10 [Unofficial]
[Introduction to Python] How to handle JSON format data
How to read an array with Python's ConfigParser
How to get article data using Qiita API
How to create a shortcut command for LINUX
[Note] How to create a Ruby development environment
How to create a Kivy 1-line input box
How to create a multi-platform app with kivy
How to read time series data in PyTorch
How to search HTML data using Beautiful Soup
How to create a Rest Api in Django
Data cleaning How to handle missing and outliers
[PyTorch] Sample ⑧ ~ How to build a complex model ~
[Note] How to create a Mac development environment
How to create random numbers with NumPy's random module
How to use fixture in Django to populate sample data associated with a user model
How to quickly create a machine learning environment using Jupyter Notebook with UbuntuServer 16.04 LTS
Quickly create a Python data analysis dashboard with Streamlit and deploy it to AWS