Python - append VS extend efficiency

前端 未结 3 693
余生分开走
余生分开走 2020-12-28 09:13

Here is some code that I wrote using Python:

from math import sqrt
abundant_list = []

for i in range(12,28123+1):
    dividor_list = [1]
    for j in range(         


        
3条回答
  •  孤独总比滥情好
    2020-12-28 09:39

    They take exact same time.

    Here is the time taken for your code:

    With dividor_list.extend([i/j,j])

    >>> 
    0:00:00.410000
    >>> 
    0:00:00.383000
    >>> 
    0:00:00.389000
    

    With dividor_list.append(i/j); dividor_list.append(j)

    >>> 
    0:00:00.400000
    >>> 
    0:00:00.390000
    >>> 
    0:00:00.381000
    

提交回复
热议问题