python为数组里的每一个元素加1的代码

在内容闲暇时间,将开发过程较好的内容段珍藏起来,下面内容段是关于python为数组里的每一个元素加1的内容,应该能对各位有帮助。
#!/usr/bin/env python
#
# [SNIPPET_NAME: Generate modified list]
# [SNIPPET_CATEGORIES: Python Core]
# [SNIPPET_DESCRIPTION: How to generate a modified list by iterating over each element of another list]
# [SNIPPET_AUTHOR: Scott Ferguson <scottwferg@gmail.com>]
# [SNIPPET_LICENSE: GPL]

first_list = range(10) # [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]

result = [x + 1 for x in first_list] # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

print result




 

posted on 2019-09-06 14:11  Westbrook46  阅读(4706)  评论(0编辑  收藏  举报