How can we enumerate list inside list of sublist?

149 Views Asked by At

I have there two list

list_ =  
[['CORAM: ThaneBench1'],
 ['1', 'CC006000000196545', 'P99000007726', 'Jennifer Nilesh Joil', 'Viva Homes Pvt. Ltd.', '30/10/2021 @ 11:00 AM', 'For Appearance'], 
['2', 'CC006000000196225', 'P51700001729', 'Sheth Developers Private Limited', 'Mr. Rahul Sirkhe and Mrs Pomy Nandy', '30/10/2021 @ 11:45 AM', 'For Appearance'],
 ['3', 'CC006000000197009', 'P51700001729', 'Sheth Developers Pvt Ltd', 'Vijay Sharma', '30/10/2021 @ 12:30 PM', 'For Appearance'],
 ['CORAM: PuneBench6'], 
['1', 'CC005000000085612', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'SHAKILA KAZI', '30/10/2021 @ 04:00 PM', 'For Appearance'],
 ['2', 'CC005000000085613', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'RAJENDRA PARHAD', '30/10/2021 @ 04:00 PM', 'For Appearance'], 
['3', 'CC005000000085614', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'UTTANKA HAZARIKA', '30/10/2021 @ 04:00 PM', 'For Appearance'], 
['4', 'CC005000000085616', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'VIKAS SRIVASTAVA', '30/10/2021 @ 04:00 PM', 'For Appearance'], 
['5', 'CC005000000085617', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'SUMAN GUPTA', '30/10/2021 @ 04:00 PM', 'For Appearance']]

i want this list be like where ever single element is present in the list append it with all next list and stop when next one element in the list is present and start next element goes to the each next of list (on end of the position)

list_ = [ ['1', 'CC006000000196545', 'P99000007726', 'Jennifer Nilesh Joil', 'Viva Homes Pvt. Ltd.', '30/10/2021 @ 11:00 AM', 'For Appearance','CORAM: ThaneBench1'],
 ['2', 'CC006000000196225', 'P51700001729', 'Sheth Developers Private Limited', 'Mr. Rahul Sirkhe and Mrs Pomy Nandy', '30/10/2021 @ 11:45 AM', 'For Appearance','CORAM: ThaneBench1'], 
['3', 'CC006000000197009', 'P51700001729', 'Sheth Developers Pvt Ltd', 'Vijay Sharma', '30/10/2021 @ 12:30 PM', 'For Appearance','CORAM: ThaneBench1'], 
['1', 'CC005000000085612', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'SHAKILA KAZI', '30/10/2021 @ 04:00 PM', 'For Appearance','CORAM: PuneBench6'],
 ['2', 'CC005000000085613', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'RAJENDRA PARHAD', '30/10/2021 @ 04:00 PM', 'For Appearance','CORAM: PuneBench6'], 
['3', 'CC005000000085614', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'UTTANKA HAZARIKA', '30/10/2021 @ 04:00 PM', 'For Appearance','CORAM: PuneBench6'], 
['4', 'CC005000000085616', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'VIKAS SRIVASTAVA', '30/10/2021 @ 04:00 PM', 'For Appearance','CORAM: PuneBench6'], 
['5', 'CC005000000085617', 'P52100002391', 'SSG REALTY AND INFRA LLP', 'SUMAN GUPTA', '30/10/2021 @ 04:00 PM', 'For Appearance','CORAM: PuneBench6']
1

There are 1 best solutions below

0
mozway On

You can use a simple loop:

suffix = []
out = []
for l in list_:
    if l[0].startswith('CORAM'):
        suffix = l
    else:
        out.append(l+suffix)
out

Output:

[['1',
  'CC006000000196545',
  'P99000007726',
  'Jennifer Nilesh Joil',
  'Viva Homes Pvt. Ltd.',
  '30/10/2021 @ 11:00 AM',
  'For Appearance',
  'CORAM: ThaneBench1'],
 ['2',
  'CC006000000196225',
  'P51700001729',
  'Sheth Developers Private Limited',
  'Mr. Rahul Sirkhe and Mrs Pomy Nandy',
  '30/10/2021 @ 11:45 AM',
  'For Appearance',
  'CORAM: ThaneBench1'],
...
]