简体   繁体   中英

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] = '' 
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, '')

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM