Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

Treat lines of a file as elements of a set

Project Description


Lines is a simple program that allows you to manipulate lines of a file as if they were members of a set. It also provides a few other useful functions to analyse such files.

Set operations

Given two files

file1 containing

a b c d

and file2 with

c d e f

It’s possible to do things like

  • Unions

lines -u file1 file2


a b c d e f
  • Intersections

lines -i file1 file2


c d
  • Difference (All elements in file1 that are not in file2).

lines -d file1 file2


a b
  • Symmetric difference (All elements present in only one of the

lines -s file1 file2


a b e f

Other Operations

These are a few other operations which I’ve found useful

  • Squeeze blanks

This operation squeezes out the blank lines in a file.

So, If you run lines –squeeze file1 where file1 looks like this

a b c



You’d get

a b c d f
  • Identify Patterns

This partitions the elements of the set into subsets all of whose members have an upper bound on the levenshtein distance from each other. This is useful to identify patterns in the input file.

So, if I have a file examples/f6 that looks like this

Archive.001-of-020.part Archive.002-of-020.part Archive.003-of-020.part Archive.004-of-020.part Archive.005-of-020.part Archive.006-of-020.part Archive.007-of-020.part .Archive.008-of-020.part.zbnrw Archive.009-of-020.part Archive.010-of-020.part Archive.011-of-020.part Archive.012-of-020.part Archive.013-of-020.part Archive.014-of-020.part Archive.015-of-020.part Archive.016-of-020.part Archive.017-of-020.part Archive.018-of-020.part Archive.019-of-020.part Archive.020-of-020.part

I can run python –patterns -l 5 examples/f6 and get

19 elements 1 elements - {‘.Archive.008-of-020.part.zbnrw’}

The -l 5 is to set the upper bound on the levenshtein distance to 5. The -p option allows us to specify an “outlier percentage”. If the number of elements in a subset is below this, it will print all the elements of the subset. This is useful to see the items that don’t match the general pattern in the file.

Release History

Release History

This version
History Node


Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
lines-0.1.0-a.tar.gz (2.6 kB) Copy SHA256 Checksum SHA256 Source Oct 8, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting