Reputation: 13
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
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