0

I have two lists:

list_one = [3 5 3 5 3 5 5 5 3 3 5 3]

and

list_two = [[2000, 2100], [2200, 2300], [2500, 2600]]

I want to alter the first number in each sublist in list_two by a corresponding number from list_one, such that

list_two = [[(2100-3), 2100], [(2300-5), 2300], [(2600-3), 2600)]

I have the following code but it is doing this in the wrong order.

new_list = []
for i in list_two:
    for k in list_one:
        a = i[1]-k
        b = i[1]
        c = [a, b]
    new_list.append(c)
mkrieger1
  • 19,194
  • 5
  • 54
  • 65
sallicap
  • 75
  • 1
  • 7

1 Answers1

0

You can do with list comprehension,

In [3]: list_two = [[2000, 2100], [2200, 2300], [2500, 2600]]                                                                                                                                               

In [4]: list_one = [3,5,3,5,3,5,5,5,3,3,5,3]                                                                                                                                                                

In [5]: [[i[0]-j, i[1]]for i,j in zip(list_two, list_one)]                                                                                                                                                  
Out[5]: [[1997, 2100], [2195, 2300], [2497, 2600]]
Rahul K P
  • 15,740
  • 4
  • 35
  • 52