~doctormo/python-snippets/lp-merge-request-example

1
2
3
4
5
6
7
8
9
10
11
12
13
#!/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]

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

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

print result