草庐IT

accumulationList

全部标签

python - 如何使用列表理解来扩展 python 中的列表?

这个问题在这里已经有了答案:list.extendandlistcomprehension[duplicate](6个答案)关闭4年前。我没有使用Python的经验,我经常编写(简化)如下所示的代码:accumulationList=[]forxinoriginalList:y=doSomething(x)accumulationList.append(y)returnaccumulationList然后在我的测试通过后,我重构为return[doSomething(x)forxinoriginalList]但假设结果有点不同,我的循环看起来像这样:accumulationList=[

python - 如何使用列表理解来扩展 python 中的列表?

这个问题在这里已经有了答案:list.extendandlistcomprehension[duplicate](6个答案)关闭4年前。我没有使用Python的经验,我经常编写(简化)如下所示的代码:accumulationList=[]forxinoriginalList:y=doSomething(x)accumulationList.append(y)returnaccumulationList然后在我的测试通过后,我重构为return[doSomething(x)forxinoriginalList]但假设结果有点不同,我的循环看起来像这样:accumulationList=[