I've hit a wall and need some help.
Context: I have a list of lists of strings.
Matrix = [['444'],
['23%'],
['A']]
For the moment, we have a list of Counts at position 0, Percentage at 1 and Significance test at 2.
The number of lists within the list changes from 3 to 2 to 1 from time to time. And the type of string within the list changes position. So I cannot assume that index 0 will always be Counts and percentage will be 1 etc.
Hence I wanted to find a way of dynamically finding out where percentage, for example, is located in the Matrix, and if its even in there.
Here is what I've written so far:
for i, row in enumerate(Matrix):
for cell in row:
if "%" in cell:
percent = i
print percent
for i, row in enumerate(Matrix):
for cell in row:
if re.search('[a-zA-Z]', cell):
sigtest = i
print sigtest
for i, row in enumerate(Matrix):
for cell in row:
if re.search('[0-9]', cell):
count = i
print count
Output:
1
2
0
1
Problem: As you can see, the problem is located with the last for loop which records the fact that index 0 and 1 contain numbers.
Whats needed: A way for the last for loop to search for numbers and numbers only, a item contains numbers and a symbol, that index should not be included.
Hope that makes sense!
thanks