Find out how to divide a file with a certain number of lines evenly

When dividing a file with a known number of lines by a specified number, find out how to divide it.

py


total=100 #Total number of lines
div = 7 #Division number

div_list = [ (total//div) + (1 if x <(total%div) else 0)  for x in range(div)]
# div_list = [15, 15, 14, 14, 14, 14, 14]

In the above example, if you divide a file with 100 lines into 7 files, You can divide it into two files with 15 lines and five files with 14 lines.

Recommended Posts

Find out how to divide a file with a certain number of lines evenly
How to put a line number at the beginning of a CSV file
How to read a CSV file with Python 2/3
I want to display only different lines of a text file with diff
python: Tips for displaying an array (list) with an index (how to find out what number an element of an array is)
How to identify the element with the smallest number of characters in a Python list?
How to find the optimal number of clusters in k-means
How to put a hyperlink to "file: // hogehoge" with sphinx-> pdf
How to display a list of installable versions with pyenv
How to find the scaling factor of a biorthogonal wavelet
Find out how to buy high-ranked Timo items with a good win rate-Part 1 API to use
How to create a config file
How to make a command to read the configuration file with pyramid
Here's a brief summary of how to get started with Django
How to find the memory address of a Pandas dataframe value
How to output the output result of the Linux man command to a file
Node.js: How to kill offspring of a process started with child_process.fork ()
[ROS2] How to play a bag file with python format launch
[EC2] How to take a screen capture of your smartphone with selenium
How to add a package with PyCharm
[Python] How to put any number of standard inputs in a list
[Introduction to Python] How to sort the contents of a list efficiently with list sort
[Python] How to read a csv file (read_csv method of pandas module)
[Completed version] Try to find out the number of residents in the town from the address list with Python
How to play a video while watching the number of frames (Mac)
Summary of how to build a LAMP + Wordpress environment with Sakura VPS
I wanted to know the number of lines in multiple files, so I tried to get it with a command
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
How to find out what kind of files are stored in S3 in Python
How to drop Google Docs in one folder in a .txt file with python
How to count the number of elements in Django and output to a template
How to apply updlock, rowlock, etc. with a combination of SQLAlchemy and SQLServer
Use twitter API to get the number of tweets related to a certain keyword
How to read a serial number file in a loop, process it, and graph it
How to get a list of files in the same directory with python
[Introduction to Python] How to get the index of data with a for statement
A new form of app that works with GitHub: How to make GitHub Apps
How to calculate the volatility of a brand
How to disguise a ZIP file as a PNG file
A simple example of how to use ArgumentParser
How to find the area of the Voronoi diagram
How to send a message to LINE with curl
Upload a large number of images to Wordpress
Convert data with shape (number of data, 1) to (number of data,) with numpy.
How to draw a 2-axis graph with pyplot
How to develop a cart app with Django
How to create a JSON file in Python
How to make a dictionary with a hierarchical structure.
[Python] How to read excel file with pandas
Find the number of days in a month
How to specify attributes with Mock of python
How to implement "named_scope" of RubyOnRails with Django
Save the object to a file with pickle
How to create a multi-platform app with kivy
Find out the day of the week with datetime
I want to write to a file with Python
How to read a file in a different directory
I tried to find out how to streamline the work flow with Excel x Python ②
How to display the modification date of a file in C language up to nanoseconds
I tried to find out how to streamline the work flow with Excel x Python ④
I tried to find out how to streamline the work flow with Excel x Python ⑤