Home > front end >  individual string list to list of string
individual string list to list of string

Time:08-29

I have a text output that has individual list,this format ['a']['b']['c'] and so on and I want to convert this list into a string put in a list, in this format ['a','b','c'].The end goal is to create a new column and append this list of strings to rows in a column.

CodePudding user response:

You can join the lists like this:

list_item = [['a'], ['b'], ['c']]
result = []
for i in list_item:
    result.append(i[0])

print(result)

The result will be this:

['a', 'b', 'c']

CodePudding user response:

You could consider using a list comprehension:

>>> old_list = [['a'], ['b'], ['c']]
>>> new_list = [lst[0] for lst in old_list]
>>> new_list
['a', 'b', 'c']
  • Related