Python List Comprehension

Source URL: N/A

Language: python

Created on: 2021-09-01 11:03:24

#           PYTHON LIST COMPREHENSION
#ordinary syntax:
numbers = []
for x in range(10):
    numbers.append(x)
print(numbers)

#LIST COMPREHENSION syntax:
numbers = [x for x in range(10)]
print(numbers)

#Both get the same result.

#Check the official documentation:
'''
https://www.w3schools.com/python/python_lists_comprehension.asp
'''
Python List Comprehension
content_copy