-1

I am making a part of code that will search for keywords in string and if it finds them, it will write them down.

I made a keyword list in a csv file and imported it to python and then made it to a list. Now, the problem is that the list isn't a completely regular list. Instead of [item1, item2, item3, etc] it outputs [[item1], [item2], [item3], [etc]]

I would like to remove the brackets [] from every item in the list and otherwise keep the list the way it was.

I have tried looking up many ways of doing this and none of them has worked for me yet, what method should I in this situation try?

MiQ
  • 39
  • 7
  • Do you flattening the list? – Pygirl Jun 09 '21 at 10:59
  • 1
    Does this answer your question? [How to make a flat list out of a list of lists?](https://stackoverflow.com/questions/952914/how-to-make-a-flat-list-out-of-a-list-of-lists) – Nouman Jun 09 '21 at 11:04
  • 1
    How are you importing from the CSV. Perhaps include the CSV contents and your current code. This issue could be resolved by importing it in a different way. – newToCoding Jun 09 '21 at 11:05
  • At first I tried all these methods on a different list that I made but now I tried these methods on the actual list imported from the csv file, and it worked! I used the post linked by @BlackThunder. Anyways thanks to everyone who replied! – MiQ Jun 09 '21 at 12:34

1 Answers1

1
list1=[[item1], [item2], [item3], [item4]]
final_list=[]
for items in list1:
    final_list.append(items[0])
print(final_list)