python 列表推导
废话不多说,直接上代码
#coding=utf-8
def getitem(index, element):
return '%d: %s' % (index, element)
def getitem2():
array = ['I', 'love', 'Python']
arrayIndex = [getitem(index, element) for index, element in enumerate(array)]
return arrayIndex
if __name__=="__main__":
a=getitem2()
print(a)
运行结果如下图:
F:\dev\python\python.exe F:/pyCharm/pratice/list_demo/demo_1.py
['0: I', '1: love', '2: Python']
Process finished with exit code 0