【发布时间】:2016-06-03 07:13:48
【问题描述】:
时间复杂度有区别吗?或者他们是一样的?我很难说(python 3.5)
list_of_dict = [{'name':'alan', 'age':5}, {'name':'alice', 'age':6}]
# first method
names = []
ages = []
for i in range(len(list_of_dict)):
names.append(list_of_dict[i]['name'])
ages.append(list_of_dict[i]['age'])
# second method
names = [x['name'] for x in list_of_dict]
ages = [x['age'] for x in list_of_dict]
对于这个问题可能微不足道,我提前道歉。我是一名学生,在我继续学习的过程中,我们非常感谢您的洞察力。
【问题讨论】:
标签: python algorithm time-complexity