I am trying to divide a list of elements which are comma separated into chunks of unequal length. How can I divide it?
list1 = [1, 2, 1]
list2 = [\"1.1.1.1\", \"
You can also use the .pop()
method like this:
list1 = [1, 2, 1]
list2 = ["1.1.1.1", "1.1.1.2", "1.1.1.3", "1.1.1.4"]
new_list = []
for chunk in list1:
new_list.append( [ list2.pop(0) for _ in range(chunk)] )
print(new_list)
# [['1.1.1.1'], ['1.1.1.2', '1.1.1.3'], ['1.1.1.4']]
This will modify the original list2.