10 Python Comprehension You should be using
Example 1: Creating a List with a Range
Traditional Way:
values = []
for x in range(10):
values.append(x)
print(values)
# [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
Using List Comprehension:
values = [x for x in range(10)]
print(values)
# [0, 1, 2, 3, 4, 5,...
avezqureshi14.hashnode.dev3 min read