303 if not config.get("macros", False):
304 print(f"{colored.fg(1)}No macros found in current config {colored.fg(15)}\n")
305 sys.exit(1)
306 commands = [current_command for current_command in config["macros"]] # Get list of commands in config307 error_threshold = 60 # The percentage of likelyhood before similar words will throw out result
308 similar_words = suggest_word.extractBests(name, commands,score_cutoff=error_threshold , limit=3) # Generate word sugestions
309 if not similar_words: # If there are not similar commands that exist in the config
It is unnecessary to use a comprehension just to loop over the iterable
and create a list
/set
/dict
out of it.
Python has a specialized set of tools for this task: the list
/set
/dict
constructors, which are faster and more readable.
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = {
abbreviation: name
for abbreviation, name in states
}
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = dict(states)