regex - Identifying Lists of Numbers With Regular Expressions in Python -


i'm working data online math tutor program, , i'd able identify features of problems. example, following question:

find median of 7 numbers in following list: [22, 13, 5, 16, 4, 12, 30] 

i'd know if

1. problem includes list,  2. how long longest list in problem is, ,  3. how many numbers in problem total.  

so problem above, has list, list 7 numbers long, , there 8 numbers in problem total.

i've written following regex script can identify positive , negative numbers , floats, can't figure out how identify series of numbers in list:

'[-+]{0,1}[0-9]+\.{0,1}(?! )[0-9]+' 

additionally, data poorly formatted, of following examples possible list of numbers can like:

[1, 2, 3] 1, 2, 3 1,2,3. 1,    2,    3,    4,    5 

i've been working on few days now, , have stopped being able make progress on it. can help? might not problem solve regex, i'm not sure how go point.

in addition answer provided alfasin, can second search find sub-strings encased in list:

s = '''1, 2, 3        [4, 5, 6]        3, 2, 1. '''  l = re.findall(r'\[.*\]', s) # number of lists in string print len(l)  # largest array length of numbers in each list found print max([re.findall(r'\d+', i) in l])  # number of numbers total in problem print re.findall(r'\d+', s) 

Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -