If you keep a public Instagram account for a side project, the audience lists usually live only inside the app. That is fine until you want a local copy you can query: who follows you, who you follow, and where the two sets do not overlap.
This is not a growth tactic. It is a small data-cleanup job. The lists contain other people's account names, so treat the files as personal data: keep them on your machine, leave them out of git, and do not publish the raw export.
Get two lists you can actually open
Instagram's interface is not built for this. You can transcribe names by hand, which falls apart after a few dozen accounts, or you can export the follower and following lists and work with them in your own tools.
One way to do that is a Chrome extension that runs inside Instagram in the browser. I work on the Gramino team, and exporting follower and following lists is one of the everyday tools described on our site. This article does not depend on a vendor-specific file layout. Whatever produced the files, you should be able to open them as text.
Before you write any code, look at the first lines.
If each line is a single account name, you already have something a script can read. If you see commas or tabs, you are looking at a table. Note the header, if there is one, and which column holds the account identifier. Do not assume a column name. Export layouts differ, and a hardcoded schema will fail on the next file.
What the script should compute
Three sets are enough:
- Names in both lists (mutual)
- Names in followers, but not in following
- Names in following, but not in followers
That is ordinary set difference. It does not tell you why someone left, and it does not detect automated accounts. Leave those judgments out of the script.
A spreadsheet can do the same three sets if you are comfortable with VLOOKUP or a join. A script is worth it when you will repeat the comparison, when the next export might be a different layout, and when you do not want the names sitting in a cloud sheet by default. Keep the code small enough that you can read all of it before you run it.
A small Python script
The script below accepts a text file (one name per line) or a CSV/TSV table. For a table, pass --column with the header of the identifier field. If you omit it and the file looks like a table, the script exits and asks you to name the column. Names are compared case-insensitively after a leading @ is stripped. Lines whose identifier starts with # are ignored.
#!/usr/bin/env python3
"""Compare two account lists without assuming a vendor-specific layout."""
from __future__ import annotations
import argparse
import csv
import io
from pathlib import Path
def normalize(name: str) -> str:
return name.strip().lstrip("@").casefold()
def parse_rows(text: str) -> list[list[str]]:
sample = text[:4096]
if not sample.strip():
return []
try:
dialect = csv.Sniffer().sniff(sample, delimiters=",\t;")
except csv.Error:
return [[line] for line in text.splitlines() if line.strip()]
reader = csv.reader(io.StringIO(text), dialect)
return [row for row in reader if any(cell.strip() for cell in row)]
def load_names(path: Path, column: str | None) -> set[str]:
rows = parse_rows(path.read_text(encoding="utf-8-sig"))
if not rows:
return set()
start = 0
index = 0
if column:
header = [cell.strip() for cell in rows[0]]
lowered = [h.casefold() for h in header]
key = column.casefold()
if key not in lowered:
raise SystemExit(f"No column named {column!r} in {path}")
index = lowered.index(key)
start = 1
elif len(rows[0]) > 1:
raise SystemExit(
f"{path} looks like a table. Pass --column with the identifier header."
)
names: set[str] = set()
for row in rows[start:]:
if index >= len(row):
continue
value = normalize(row[index])
if value and not value.startswith("#"):
names.add(value)
return names
def main() -> None:
parser = argparse.ArgumentParser(
description="Compare follower and following account lists."
)
parser.add_argument("followers", type=Path)
parser.add_argument("following", type=Path)
parser.add_argument(
"--column",
help="Identifier column header when the files are CSV or TSV tables",
)
args = parser.parse_args()
followers = load_names(args.followers, args.column)
following = load_names(args.following, args.column)
only_followers = followers - following
only_following = following - followers
mutual = followers & following
print(f"followers: {len(followers)}")
print(f"following: {len(following)}")
print(f"mutual: {len(mutual)}")
print(f"in followers only: {len(only_followers)}")
print(f"in following only: {len(only_following)}")
print("\nin followers only:")
for name in sorted(only_followers):
print(f" {name}")
print("in following only:")
for name in sorted(only_following):
print(f" {name}")
if __name__ == "__main__":
main()
Save it as compare_lists.py. The examples below use made-up names so you can see the shape of the output. They are not from a real account.
Plain text, one name per line:
python3 compare_lists.py followers.txt following.txt
If followers.txt contains alice, bob, and carol, and following.txt contains bob, carol, and dave, the counts look like this:
followers: 3
following: 3
mutual: 2
in followers only: 1
in following only: 1
in followers only:
alice
in following only:
dave
For a table with a header, name the column:
python3 compare_lists.py followers.csv following.csv --column username
The same three names, written as alice, bob, and @Alice in a username column, collapse to one account because the script strips @ and ignores case.
Keep the files off the public internet
Add a pattern such as followers.* and following.* to .gitignore before you run anything in a repository. Store the files outside the project if you can.
Do not mail the raw lists to yourself through a work inbox you do not control. Do not paste them into a chat. If you need a second machine, copy the files directly and delete the extra copy when you are done.
The script prints account names. Redirect the output to a file only if that file will also stay local:
python3 compare_lists.py followers.txt following.txt > /tmp/ig-diff.txt
Delete /tmp/ig-diff.txt when you have finished reading it.
What not to automate next
It is tempting to turn the "following only" list into a bulk unfollow. Don't. This workflow stops at a local report. Decisions about who to follow or remove still belong in the official Instagram interface, one account at a time, according to Instagram's terms.
The same limit applies to scoring accounts as bots in your own script. You do not have enough signal in a username list to do that honestly. If a product offers a separate in-app review of suspicious accounts by risk level, treat that as a review step, not as a number this script should invent.
Once you can load both lists, you already have a reusable habit: export, compare, read the diff, then put the files away.
Disclosure: I work on the Gramino team. Gramino is a Chrome extension for Instagram, not an official Instagram or Meta product. This article is about comparing exported lists locally; it does not claim results or follower growth.
Top comments (0)