I want to create a "list of lists" list object in Python.
So that I can initialize a Pandas DataFrame from this list of lists.
Here's my code:
import os
import re
result = []
final_output = []
output = os.popen('kubectl get namespaces').read()
result = output.split('\n')
def remove(string):
pattern = re.compile(r'\s+')
return re.sub(pattern, ',', string)
for item in result:
final_output.append(remove(item))
print(final_output)
The problem is, my data is currently in the following list format:
[
'[resight,True,345]',
'[creekstuff,True,345]',
'[digoneutism,True,567]',
'[directorates,True,354]',
'[bedsheet,True,499]'
]
I want it to appear as list of lists follows:
[
['resight','True','345'],
['creekstuff','True','345'],
['digoneutism','True','567'],
['directorates','True','354'],
['bedsheet','True','499']
]
So, it seems what needs to be done is:
- Drop the single quote outside the square bracket
- Have a single quote wrap each word.
But, how to achieve this?