I have a string, where I am only interested in getting the numbers encapsulated in single quotes.
For instance if I have the string "hsa456456 ['1', '2', ...]
I only want the 1 and the 2 and whatever numbers follow
To do this, I have the following code:
import re
#pattern = re.compile("dog")
#l = re.findall(pattern, "dog dog dog")
#valuepattern=re.compile('\'\d{1,6}\'')
valuepattern = re.compile('\'\d+\'')
li = []
s = "hsa04012 [[['7039', '1956', '1398', '25'], ['7039', '1956', '1399', '25']], [['1839', '1956', '1398', '25'], ['1839', '1956', '1399', '25']], [['1399', '25']], [['1398', '25']], [['727738', '1956', '1398', '25'], ['727738', '1956', '1399', '25']], [['1956', '1398', '25'], ['1956', '1399', '25']], [['1950', '1956', '1398', '25'], ['1950', '1956', '1399', '25']], [['374', '1956', '1398', '25'], ['374', '1956', '1399', '25']], [['2069', '1956', '1398', '25'], ['2069', '1956', '1399', '25']], [['685', '1956', '1398', '25'], ['685', '1956', '1399', '25']]]"
#if match:
# print match.group()
#else:
# print "no match"
l = re.findall(valuepattern, s)
#print l
for item in l:
li.append(item.strip("'"))
#print item
for item in li:
print item
My areas of interest is to minimize the number of lists. Right now, I use two l and li. I take the item from l and append it to li after stripping. I was curious if there was a way to accomplish this operation all within one list... without the need for li and then appending.