0

I have a question, how can we create a second list in python, which every content of this list is about 10 larger than first list. I can't solve it by loop(for). For example:

l1[2] = 2 
 l2[2] = 12

or

 l1 = [0,1,2,3]
 l2 = [10,11,12,13]

Thank You

Chetan Ameta
  • 7,696
  • 3
  • 29
  • 44
  • 3
    Just do `l2 = [v + 10 for v in l1]`. It's called a list comprehension. – Tom Karzes Oct 12 '20 at 09:33
  • 2
    Does this answer your question? [Sum one number to every element in a list (or array) in Python](https://stackoverflow.com/questions/5754571/sum-one-number-to-every-element-in-a-list-or-array-in-python) – IoaTzimas Oct 12 '20 at 09:34

1 Answers1

2

Just try (This is a list comprehension, where it iterates over the first list and adds 10 to each item):

l2 = [x+10 for x in l1]
print(l2)

This is the short version of:

l2 = []
for i in l1:
    l2.append(i+10)
S.D.
  • 2,486
  • 1
  • 16
  • 23
Wasif
  • 14,755
  • 3
  • 14
  • 34