-1

I have the following input:

[ ['A(x) | B(x)'],['Function(x,y) | K(x)'] ]

Each list within the list of list has a space before and after the character "|". How can I remove this to get the following result?

[ ['A(x)|B(x)'],['Function(x,y)|K(x)'] ]

I tried the following:

list=[]
k1=[]
for i in sentence:
    k1="".join(i).replace(" ","")
    list.append(k1)

result=[[i] for i in list]
Gayathri Ravi
  • 1,459
  • 1
  • 12
  • 18

1 Answers1

0

Try this:

>>> a_list = [['A(x) | B(x)'], ['Function(x,y) | K(x)']]
>>> result = [[''.join(''.join(sub).split())] for sub in a_list]
>>> result
[['A(x)|B(x)'], ['Function(x,y)|K(x)']]
srikavineehari
  • 2,502
  • 1
  • 11
  • 21