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 ]
# [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




 

转载于:https://www.cnblogs.com/Westbrook46/p/11474536.html

你可能感兴趣的:(python为数组里的每一个元素加1的代码)