0

I have a list with a strange structure as follows:

List_input = [['statment01'], ['statment02'], ['statment03'],.....['statement1000']]

I need to remove the inner brackets [] and the single notations of each item.

The required output list is like this:

List_output = ["statment01", "statment02", "statment03",....., "statement1000"]

Could anyone help with this?

Mohsen Ali
  • 655
  • 1
  • 9
  • 30
  • 3
    Does this answer your question? [join list of lists in python](https://stackoverflow.com/questions/716477/join-list-of-lists-in-python) – PacketLoss Jan 17 '20 at 05:11
  • 1
    Does this answer your question? [How to make a flat list out of list of lists?](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-list-of-lists) – Aiden Ray Jan 17 '20 at 05:15

2 Answers2

1

I hope this is what u r expecting:

def remove_nest(l): 
    for i in l: 
        if type(i) == list: 
            remove_nest(i) 
        else: 
            output.append(i) 

l = [[1,2,3],[4,5,6],[6,7,8]] 
output = []    
print ('The given list: ', l) 
remove_nest(l) 
print ('The list after removing nesting: ', output) 

OUTPUT:

The given list:  [[1, 2, 3], [4, 5, 6], [6, 7, 8]]
The list after removing nesting:  [1, 2, 3, 4, 5, 6, 6, 7, 8]
Amaresh S M
  • 2,936
  • 2
  • 13
  • 25
1

Just iterate over list and append it to new array.

List_output = []
for i in List_input:
    List_output.append(i[0])
Santhosh Kumar
  • 543
  • 8
  • 22