Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

text file sort by first item in each row

fn = 'filename.txt'
sorted_fn = 'sorted_filename.txt'

with open(fn,'r') as first_file:
    rows = first_file.readlines()
    sorted_rows = sorted(rows, key=lambda x: int(x.split()[0]), reverse=False)
    with open(sorted_fn,'w') as second_file:
        for row in sorted_rows:
            second_file.write(row)
Comment

PREVIOUS NEXT
Code Example
Python :: python generic class inheritance 
Python :: PyQt5 change keyboard/tab behaviour in a table 
Python :: databases not showing in odoo 13 
Python :: Make Latest pyhton as default in mac 
Python :: numpy create array with infinities 
Python :: xmgrace conditions 
Python :: df.iterrows write to column 
Python :: Cannot seem to use import time and import datetime in same script in Python 
Python :: python monats liste 
Python :: What is the expected value of print to this program X = 2 Y = 3 Z = X + Y print(Y) #Z 
Python :: why does async def not work python 
Python :: how to make api check multiple status using drf 
Python :: host python discord bot free 
Python :: add label on choropleth map python 
Python :: crop a video opencv 
Python :: how to replace zero with null in python 
Python :: multivariate classification python 
Python :: alan watts 
Python :: dask dataframe csv tutorial 
Python :: Logistic Regression with a Neural Network mindset python example 
Python :: make image to string to use in tkinter 
Python :: numpy bitwise_or multiple images 
Python :: panda3d attach to bone 
Python :: fibonacci sequence script python 
Python :: query dict immuteable 
Python :: problems on loops and if else statements 
Python :: json timestamp to date python 
Python :: python paragraph Pypi 
Python :: how to add an symbol to a certain part of a list python 
Python :: reolace text python 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =