[ create a new paste ] login | about

Link: http://codepad.org/zWExcuvj    [ raw code | output | fork ]

Python, pasted on Sep 29:
1
2
3
4
5
6
7
8
9
10
import re
def get_attr(str, attr):
    m = re.search(attr + r'=(\w+)', str)
    return None if not m else m.group(1)

str = 'type=weaksubj len=1 word1=wrestle pos1=verb stemmed1=y priorpolarity=negative'

print get_attr(str, 'word1')  # wrestle
print get_attr(str, 'type')   # weaksubj
print get_attr(str, 'foo')    # None


Output:
1
2
3
wrestle
weaksubj
None


Create a new paste based on this one


Comments: