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 ▸

Whats the output of "for i in "hello world": print(i)" and why/how is this achieved


With the help of Pandas and Numpy library create a DataFrame with the columns "Name", "Surname", "Age" and "Gender", create as many rows as you want. Print out the result.


Write a function s(n) that will return a list of the first n squares.


How do I use for loops in Python?