Unnecessary use of a comprehension, use list(index) instead.
123 #Timestamp buttons
124 sorted_df = df.sort_values(by=['Smoothed Sync Error'], ascending=False).round(2).head(5)
125 index = sorted_df.head(5).index
126 top5imp = [i for i in index]127 timestamps = sorted_df['Time'].to_list()
128 sync = sorted_df['Smoothed Sync Error'].to_list()
129
Description
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.
Bad practice
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = {
abbreviation: name
for abbreviation, name in states
}
Recommended
states = [
('AL', 'Alabama'),
('AK', 'Alaska'),
('AZ', 'Arizona'),
('AR', 'Arkansas'),
('CA', 'California'),
# ...
]
abbreviations_to_names = dict(states)