How can you take a list of numbers and add 3 to every number in the list using only one line of code?

If the list is l1, we can create a new list l2 with all the numbers within being 3 more than each number in l2 by using a list comprehension as follows:

l2 = [x+3 for x in l1]

TD

Related Python Mentoring answers

All answers ▸

Explain how you would write a python program that takes a rectangle and a point in a 2D space as command-line arguments and checks if they intersect.


Ask the user for a number and output the smallest divisor, bigger than one, for the inputted number. Output "Prime" if the number is a prime number.


What are recursive functions and when should they be used?


Write a Python script to take a product name as input and then automatically google search reviews for it and open the top 3 search results in different tabs