list
call - write as literal126 title = list()
127 short = list()
128 crdthr = list()
129 section = list()130 instructor = list()
131 for col in worksheet['C']:
132 if(col.value != None):
list
call - write as literal121 worksheet = wb["BATCH " + str(student_batch)]
122 print(worksheet)
123
124 excel_data = list()125 code = list()
126 title = list()
127 short = list()
list
call - write as literal127 short = list()
128 crdthr = list()
129 section = list()
130 instructor = list()131 for col in worksheet['C']:
132 if(col.value != None):
133 code.append(col.value)
list
call - write as literal125 code = list()
126 title = list()
127 short = list()
128 crdthr = list()129 section = list()
130 instructor = list()
131 for col in worksheet['C']:
list
call - write as literal124 excel_data = list()
125 code = list()
126 title = list()
127 short = list()128 crdthr = list()
129 section = list()
130 instructor = list()
Using the literal syntax can give minor performance bumps compared to using function calls to create dict
, list
and tuple
.
In [1]: timeit.timeit(stmt="dict()", number=100000000)
Out[1]: 9.560388602000103
In [2]: timeit.timeit(stmt="{}", number=100000000)
Out[2]: 1.685333584000091
In [3]: timeit.timeit(stmt="tuple()", number=100000000)
Out[3]: 4.509182139000131
In [4]: timeit.timeit(stmt="()", number=100000000)
Out[4]: 0.5455615430000762
In [5]: timeit.timeit(stmt="list()", number=100000000)
Out[5]: 7.356000728000254
In [6]: timeit.timeit(stmt="[]", number=100000000)
Out[6]: 1.573771306999788
This is because here, the name dict
must be looked up in the global scope in case it has been rebound.
Same goes for the other two types list()
and tuple()
.