gpt-3.5-turbo-0125· OpenAI WildChat-4.8M (AI2)
make a simple example of list comrehension in python
- User
make a simple example of list comrehension in python
- Assistant
Example of list comprehension in Python
Create a list of numbers
numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Use list comprehension to create a new list containing only even numbers
even_numbers = [num for num in numbers if num % 2 == 0]
Print the new list
print(even_numbers) # Output: [2, 4, 6, 8, 10]