CodeFaster

Share this post
Quick tip: alphabetize
codefaster.substack.com

Quick tip: alphabetize

Tyler Adams
Jun 3, 2021
2
2
Share this post
Quick tip: alphabetize
codefaster.substack.com

If you have a list, say of imports, where there is no semantic meaning in the ordering, alphabetize it. Alphabetizing makes it easier to find duplicates.

For example

Unsorted

Find the duplicate:

import os
import argparse
import copy
import sys
import datetime
import selenium.webdriver.support.expected_conditions
import datafetcher
import passlib.hash
import multiprocessing
import db
import ttest
import backtester
import numpy
import json
import serializers
import errors
import sys
import pytest
import traceback
import time
import selenium.webdriver

Sorted

Find the duplicate:

import argparse
import backtester
import copy
import datafetcher
import db
import datetime
import errors
import json
import multiprocessing
import numpy
import os
import passlib.hash
import pytest
import selenium.webdriver
import selenium.webdriver.support.expected_conditions
import serializers
import sys
import sys
import time
import traceback
import ttest

2
Share this post
Quick tip: alphabetize
codefaster.substack.com
2 Comments

Create your profile

0 subscriptions will be displayed on your profile (edit)

Skip for now

Only paid subscribers can comment on this post

Already a paid subscriber? Sign in

Check your email

For your security, we need to re-authenticate you.

Click the link we sent to , or click here to sign in.

Andrew Judson
Writes Andrew’s Newsletter Jun 3, 2021

I'd go one step further - use an editor or an IDE that is smart enough to deduplicate the imports automatically and reorder them alphabetically for you

Expand full comment
ReplyCollapse
1 reply by Tyler Adams
1 more comments…
TopNewCommunity

No posts

Ready for more?

© 2022 Tyler Adams
Privacy ∙ Terms ∙ Collection notice
Publish on Substack Get the app
Substack is the home for great writing