PenDragon
PenDragon

Reputation: 13

Comprehension list or map to improve performance?

Hello I'm trying to improve the performance of my code (find out a nice article here: http://leadsift.com/loop-map-list-comprehension/ )

And I'd like to know if I can use a comprehension list in this part of my code:

for fmt in excels:
    xls_list.add(fmt)
    df_dict[fmt] = ''

Upvotes: 0

Views: 55

Answers (1)

Adirio
Adirio

Reputation: 5286

excels = ['1.xls', '2.xls']
xls_list = set()
for fmt in excels:
    xls_list.add(fmt)
    df_dict[fmt] = ''

could be trasnformed into:

xls_list = set(excels)
df_dict = dict.fromkeys(excels, '')

Upvotes: 1

Related Questions