I have a script in a For loop that builds a list of lists with the results of my search. To each list I need to add a "variable" value. This is my code:
root = ET.fromstring(resp)
data = root.findall('.//row')
for datum in data:
entries = datum.findall('.//col')
datos.append([entry.text.strip()
for entry in entries[:5]])
I get the following result:
[['peras', '20', 'Acme'], ['bananas', '35', 'Zero'], ['sandias', '45', 'Lion']]
I want to get the following result by adding a new value to the end of each list:
[['peras', '20', 'Acme', 'AR'], ['bananas', '35', 'Zero', 'UY'], ['sandias', '45', 'Lion', 'BR']]
I am trying the following:
datos.append(codigo)
But the new value is added to me outside of each list:
[['peras', '20', 'Acme'], 'AR', ['bananas', '35', 'Zero'], 'UY', ['sandias', '45', 'Lion'], 'BR']
I'm using Python 3.6. Could you give me a hand? Thank you very much
It's not quite clear where your data lists come from, I'm guessing from XPath queries to an XML document. In any case, my answer goes along the lines of how to put together the lists you intend to put together, without going into details about where they come from.
Basically I'm assuming you have a list with partial results:
and another with additional data that is what you want to insert:
One way to put them together as you intend would be: