is there a way to combine the items with the same number as the first one that you want to delete?

May not be the best method, but maybe this helps you.

lst = ['2. Text','Text1',
 'Text2','2.1. Text3','Text4']

new_lst = []
nested_lst = []

for el in lst:
  if el[0].isdigit() and nested_lst != []:
    new_lst.append(nested_lst)
    nested_lst = []

  nested_lst.append(el)

new_lst.append(nested_lst)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top