Jul-11-2019, 12:56 PM
(This post was last modified: Jul-11-2019, 12:57 PM by rockproper.)
I am trying to iterate through a list of list and increase the first element in each sublist until it matches an integer on another list...
[[2, 13, 22, 40], [8, 13, 22, 40], [24, 13, 22, 40]]
(Nothing is getting modified) My desired output is:
[[5, 13, 22, 40], [10, 13, 22, 40], [30, 13, 22, 40]]
(so that the first integer is increased until it matches an integer on the reference_list)
I have dabbled using the set function but I can't seem to get that to work.
Any ideas are appreciated!
list1=[[2,13,22,40],[8,13,22,40],[24,13,22,40]] reference_list=[5, 10, 30] for i in list1: while i[0]!=i in reference_list: i[0]=i[0]+1 print(list1)Right now my output is:
[[2, 13, 22, 40], [8, 13, 22, 40], [24, 13, 22, 40]]
(Nothing is getting modified) My desired output is:
[[5, 13, 22, 40], [10, 13, 22, 40], [30, 13, 22, 40]]
(so that the first integer is increased until it matches an integer on the reference_list)
I have dabbled using the set function but I can't seem to get that to work.
Any ideas are appreciated!