List Comprehension

Syntax: [ expression for elem in list ]

# List Comprehension Example Code
one_to_ten = [1,2,3,4,5,6,7,8,9,10]
multiplier = int(input('Enter any number\n'))
result_of_list_comprehension = [element*multiplier for element in one_to_ten]
print(f'Multiplication Table of {multiplier}, is\n{result_of_list_comprehension}')

Example: Making list of even numbers from previous list (without list comprehension)

input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7]
output_list = []
for var in input_list:
    if var % 2 == 0:
        output_list.append(var)
print(output_list)

Using list comprehension now

input_list = [1, 2, 3, 4, 4, 5, 6, 7, 7]
list_using_comp = [var for var in input_list if var % 2 == 0]
 print(list_using_comp)
# Output for both- [2, 4, 4, 6]