In the competition for worst variable name, the name 'list' has long held the championship.
Now we have a new champion, 'data'.
(At least the name 'datos' might possibly be the name of a small island off the Greek coast populated by a tribe of Amazon women coders.)
What's wrong with such names, you ask?
Those names are useless in helping to distinguish among the possible types, purposes, quantities, and meanings of whatever such variables hold.
Your 'data' variable holds a table of some sort, with rows containing 2 columns, the first colun is some useless attribute name, and the second column is the value of that attribute.
You are doing nested selects, and I am not convinced you are using the right indices for each select at each level.
This is a case where local variables, well named, would help make clear what is happening.
Local variables can act as stepping stones in your fast moving stream of thought.
Without them, it is too easy to get swept under and drown in confusion.
Before I can attempt to understand your code, I would need to see:
- a descriptive variable name for the collection of records in the variable formerly known as 'data', like 'cheeses'
- a local variable for the currently selected row in the previous item in this list, like 'current_cheese'
- a local variable name for column 1 of the current row, like 'cheese_attribute_name' (country?)
- a local variable name for column 2 of the current row, like 'cheese_attribute_value' (France?)