This might work:
list1 = [1,2,6]
list2 = []
n = 10
list1 = sorted(list1, reverse=True) # sort list descending order
for i in list1: # for each item in list1
list2.append(i) # add the item to list2
while not sum(list2) > n: # while sum of list2 is less than n
list2.append(i) # keep adding the same element
if sum(list2) > n: # if sum of list2 is more than n
list2.pop() # remove the last element added
list2.sort() # sort list ascending order
print(list2) # [2, 2, 6]
Works for the given list1
.
Might need to test on different length and numbers of list1
.